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

来源:互联网 发布:mac mini 更新系统 编辑:程序博客网 时间:2024/05/22 14:35
;ml /coff demo.asm /link /subsystem:windows /entry:main user32.lib kernel32.lib.486;说明使用的指令集.model flat,stdcall;内存为平坦模型,函数调用规则为stacalloption casemap:none;大小写敏感; 函数原型声明MessageBoxA PROTO :dword,:dword,:dword,:dwordRegisterClassExA proto :dwordCreateWindowExA proto :dword,:dword,:dword,:dword,:dword,:dword,:dword,:dword,:dword,:dword,:dword,:dwordShowWindow proto :dword,:dwordUpdateWindow proto :dwordDefWindowProcA proto :dword,:dword,:dword,:dwordGetMessageA proto :dword,:dword,:dword,:dwordTranslateMessage proto :dwordDispatchMessageA proto :dwordExitProcess proto :dword; 数据结构定义WNDCLASSEXA STRUC cbSizedd ? styledd ?lpfnWndProc dd ?cbClsExtradd ?cbWndExtradd ?hInstancedd ?hIcondd ?hCursordd ?hbrBackgrounddd ?lpszMenuNamedd ?lpszClassNamedd ?hIconSmdd ?WNDCLASSEXA ENDS MSG STRUC hwnd dd ?    message dd ?    wParam dd ?    lParam dd ?    time dd ?    pt dd ?MSG ENDS;数据段声明.dataszClassName db 'MSGWND',0wceWNDCLASSEXA <0>msg MSG<0>hInstance dd ? ;代码段.codeMsgProc proc;序言mov edi, edipush ebpmov ebp,espmov eax, [ebp+0ch]; 比较Msg如果是 WM_DESTROY 消息则退出进程cmp eax, 2jne lablepush 0call ExitProcesslable:push [ebp+14h]push [ebp+10h]push [ebp+0ch]push [ebp+8] call DefWindowProcApop ebpret 16MsgProc endpRegister procxor eax, eaxmov wce.cbClsExtra, eaxmov wce.cbWndExtra, eaxmov wce.hCursor, eaxmov wce.hIcon, eaxmov wce.hIconSm, eaxmov eax, 30hmov wce.cbSize, eaxmov eax, 3hmov wce.style, eaxmov eax, 11hmov wce.hbrBackground, eaxmov eax, dword ptr hInstancemov wce.hInstance, eaxlea eax, MsgProcmov wce.lpfnWndProc, eaxlea eax, offset szClassNamemov wce.lpszClassName, eaxxor eax,eaxmov wce.lpszMenuName, eaxlea eax, wcepush eaxcall RegisterClassExAret 4Register endpmain proc ;int 3mov edi, edipush ebpmov ebp,espmov eax, [ebp+8]mov hInstance, eaxlea eax,wcepush eaxcall Register; Create Windowpush 0push 0 ; hInstancepush 0push 0push 64hpush 0fahpush 80000000hpush 80000000hpush 0CF0000hlea eax, offset szClassNamepush eaxpush eaxpush 0call CreateWindowExApush eaxpush 5push eaxcall ShowWindowcall UpdateWindowlable:push 0push 0push 0lea eax, offset msgpush eaxcall GetMessageAtest eax,eaxje lable_endlea eax, offset msgpush eaxpush eaxcall TranslateMessagecall DispatchMessageAjmp lablepop ebplable_end:retmain endpend


                                             
0 0
原创粉丝点击