.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
include gdi32.inc
includelib gdi32.lib
includelib user32.lib
includelib kernel32.lib
;--------------------------------------------------------------------------------
.data
ClassName db 'WinClass',0
AppName db '第一个程序',0
.data?
hInstance HINSTANCE ?
;--------------------------------------------------------------------------------
.code
start:
call WinMain
invoke ExitProcess,NULL
;--------------------------------------------------------------------------------
WinMain proc
LOCAL wc:WNDCLASSEX ;窗口结构体
LOCAL msg:MSG ;消息结构体
LOCAL hwnd:HWND ;窗口句柄
;获取本程序 模块句柄
invoke GetModuleHandle,NULL
mov hInstance,eax
;填表
mov wc.cbSize,offset WNDCLASSEX
mov wc.style ,2 or 1
mov wc.lpfnWndProc,offset WinMainProc
mov wc.hInstance,offset hInstance
mov wc.hbrBackground,5
mov wc.lpszClassName,offset ClassName
;获取本程序图标句柄
invoke LoadIcon,NULL,NULL
mov wc.hIcon,eax
mov wc.hIconSm,eax
;获取本程序光标句柄
invoke LoadCursor,NULL,NULL
mov wc.hCursor,eax
;注册窗口
invoke RegisterClassEx,addr wc
;创建窗口
invoke CreateWindowEx,NULL,addr ClassName ,addr AppName,WS_OVERLAPPEDWINDOW,0,0,500,500,NULL,NULL,hInstance,NULL
mov hwnd,eax
;显示
invoke ShowWindow,hwnd,1
;刷新
invoke UpdateWindow,hwnd
;消息机制
.while 1
invoke GetMessage,addr msg,NULL,0,0
.if(!eax)
.break
.endif
invoke TranslateMessage,addr msg ;翻译
invoke DispatchMessage,addr msg ;发送
.endw
ret
WinMain endp
;--------------------------------------------------------------------------------
WinMainProc Proc hwnd:HWND,msg:UINT,wparam:WPARAM,lparam:LPARAM
.if msg==WM_DESTROY
invoke PostQuitMessage,NULL ;终止进程
.elseif msg==WM_CREATE
.else
;这个函数是默认的窗口处理函数,我们可以把不关心的消息都丢给它来处理
invoke DefWindowProc,hwnd,msg,wparam,lparam
.endif
ret
WinMainProc endp
;--------------------------------------------------------------------------------
end start