Steward
分享是一種喜悅、更是一種幸福
程式語言 - MASM32 - Single Document Interface (SDI) - Create Window
參考資訊:
http://winapi.freetechsecrets.com/win32/
https://github.com/gammasoft71/Examples_Win32
http://masm32.com/board/index.php?topic=3584.0
Windows的視窗可以分成:Dialog、Single Document Interface(SDI)、Multiple Document Interface(MDI)三種類別,相對於SDI、MDI,Dialog類別是比較容易上手學習的一個類別,相當適合初次學習Windows視窗設計的使用者,而Windows視窗程式設計的核心就是圍繞着事件處理(處理Message),任何的視窗設定或者溝通都是以事件導向為原則,因此,寫出一個簡單的視窗框架,將有助於了解Windows視窗程式的運作
main.asm
.386
.model flat,stdcall
option casemap:none
include c:\masm32\include\windows.inc
include c:\masm32\include\kernel32.inc
include c:\masm32\include\user32.inc
includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib
.data
szName BYTE "main",0
hInstance DWORD 0
pCmdLine DWORD 0
wndClass WNDCLASS <0>
.code
WinMain proc hInst:DWORD, hPrevInst:DWORD, CmdLine:DWORD, CmdShow:DWORD
local msg:MSG
mov wndClass.lpfnWndProc, DefWindowProc
mov wndClass.lpszClassName, offset szName
invoke RegisterClass, offset wndClass
invoke CreateWindowEx, WS_EX_LEFT, offset szName, offset szName, WS_OVERLAPPEDWINDOW or WS_VISIBLE, 0, 0, 320, 240, NULL, NULL, NULL, NULL
@@:
invoke GetMessage, addr msg, NULL, 0, 0
cmp eax, 0
je @f
invoke DispatchMessage, addr msg
jmp @b
@@:
mov eax, msg.wParam
ret
WinMain endp
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke GetCommandLine
mov pCmdLine, eax
invoke WinMain, hInstance, NULL, pCmdLine, SW_SHOWDEFAULT
invoke ExitProcess, 0
end start
完成