;ml /coff demo.asm /link /subsystem:windows /entry:main user32.lib kernel32.lib
.486 ;说明使用的指令集
.model flat,stdcall ;内存为平坦模型,函数调用规则为stacall
option casemap:none ;大小写敏感
; 函数原型声明
MessageBoxA PROTO :dword,:dword,:dword,:dword
RegisterClassExA proto :dword
CreateWindowExA proto :dword,:dword,:dword,:dword,:dword,:dword,:dword,:dword,:dword,:dword,:dword,:dword
ShowWindow proto :dword,:dword
UpdateWindow proto :dword
DefWindowProcA proto :dword,:dword,:dword,:dword
GetMessageA proto :dword,:dword,:dword,:dword
TranslateMessage proto :dword
DispatchMessageA proto :dword
ExitProcess proto :dword
; 数据结构定义
WNDCLASSEXA STRUC
cbSize dd ?
style dd ?
lpfnWndProc dd ?
cbClsExtra dd ?
cbWndExtra dd ?
hInstance dd ?
hIcon dd ?
hCursor dd ?
hbrBackground dd ?
lpszMenuName dd ?
lpszClassName dd ?
hIconSm dd ?
WNDCLASSEXA ENDS
MSG STRUC
hwnd dd ?
message dd ?
wParam dd ?
lParam dd ?
time dd ?
pt dd ?
MSG ENDS
;数据段声明
.data
szClassName db 'MSGWND',0
wce WNDCLASSEXA <0>
msg MSG <0>
hInstance dd ?
;代码段
.code
MsgProc proc
;序言
mov edi, edi
push ebp
mov ebp,esp
mov eax, [ebp+0ch] ; 比较Msg如果是 WM_DESTROY 消息则退出进程
cmp eax, 2
jne lable
push 0
call ExitProcess
lable:
push [ebp+14h]
push [ebp+10h]
push [ebp+0ch]
push [ebp+8]
call DefWindowProcA
pop ebp
ret 16
MsgProc endp
Register proc
xor eax, eax
mov wce.cbClsExtra, eax
mov wce.cbWndExtra, eax
mov wce.hCursor, eax
mov wce.hIcon, eax
mov wce.hIconSm, eax
mov eax, 30h
mov wce.cbSize, eax
mov eax, 3h
mov wce.style, eax
mov eax, 11h
mov wce.hbrBackground, eax
mov eax, dword ptr hInstance
mov wce.hInstance, eax
lea eax, MsgProc
mov wce.lpfnWndProc, eax
lea eax, offset szClassName
mov wce.lpszClassName, eax
xor eax,eax
mov wce.lpszMenuName, eax
lea eax, wce
push eax
call RegisterClassExA
ret 4
Register endp
main proc
;int 3
mov edi, edi
push ebp
mov ebp,esp
mov eax, [ebp+8]
mov hInstance, eax
lea eax,wce
push eax
call Register
; Create Window
push 0
push 0 ; hInstance
push 0
push 0
push 64h
push 0fah
push 80000000h
push 80000000h
push 0CF0000h
lea eax, offset szClassName
push eax
push eax
push 0
call CreateWindowExA
push eax
push 5
push eax
call ShowWindow
call UpdateWindow
lable:
push 0
push 0
push 0
lea eax, offset msg
push eax
call GetMessageA
test eax,eax
je lable_end
lea eax, offset msg
push eax
push eax
call TranslateMessage
call DispatchMessageA
jmp lable
pop ebp
lable_end:
ret
main endp
end