利用純彙編寫乙個WIN32的視窗程式

2021-07-14 14:21:15 字數 3414 閱讀 5458

;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

registerclas***a 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

; 資料結構定義

wndclas***a struc

cbsize dd ?

style dd ?

lpfnwndproc dd ?

cbcl***tra dd ?

cbwndextra dd ?

hinstance dd ?

hicon dd ?

hcursor dd ?

hbrbackground dd ?

lpszmenuname dd ?

lpszclassname dd ?

hiconsm dd ?

wndclas***a ends

msg struc

hwnd dd ?

message dd ?

wparam dd ?

lparam dd ?

time dd ?

pt dd ?

msg ends

;資料段宣告

.data

szclassname db 'msgwnd',0

wce wndclas***a <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.cbcl***tra, 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 registerclas***a

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:

retmain endp

end

如何建立乙個win32程式

首先要寫類似於main函式的winmain,int winapi winmain hinstance hinstance,hinstance hprevinstance,lpstr lpcmdline,int ncmdshow winapi是幹什麼的呢?它是呼叫宣告,相當於 stdcal。c 預設的...

建立乙個win32視窗程式

include stdafx.h 2hinstance g hinst null 3 視窗處理函式 lresult callback wndproc hwnd hwnd,視窗控制代碼 uint nmsg,視窗訊息id wparam wparam,訊息傳來的兩個引數 lparam lparam 返回預...

第乙個Win32程式

第乙個win32視窗.cpp 定義應用程式的入口點。include stdafx.h include 第乙個win32視窗.h include include stdio.h hwnd hwnd pchar szoutbuff lresult callback wndproc hwnd hwnd,u...