利用纯汇编写一个WIN32的窗口程序

;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
	


 

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值