Steward
分享是一種喜悅、更是一種幸福
程式語言 - Flat Assembler (FASM) - Win32 API - Single Document Interface (SDI) - Create Window
參考資訊:
https://board.flatassembler.net/
Windows的視窗可以分成:Dialog、Single Document Interface(SDI)、Multiple Document Interface(MDI)三種類別,相對於SDI、MDI,Dialog類別是比較容易上手學習的一個類別,相當適合初次學習Windows視窗設計的使用者,而Windows視窗程式設計的核心就是圍繞着事件處理(處理Message),任何的視窗設定或者溝通都是以事件導向為原則,因此,寫出一個簡單的視窗框架,將有助於了解Windows視窗程式的運作
main.asm
format PE GUI 4.0
entry start
include "c:\fasm\include\win32a.inc"
include "c:\fasm\include\api\kernel32.inc"
include "c:\fasm\include\api\gdi32.inc"
include "c:\fasm\include\api\user32.inc"
section ".idata" import data readable writeable
library \
gdi32, "gdi32.dll", \
user32, "user32.dll", \
kernel32, "kernel32.dll"
section ".data" data readable writeable
hInstance DD 0
pCommand DD 0
szName DB "main",0
pWndClass WNDCLASS <0>
section ".text" code readable executable
proc WinMain hInst, hPrevInst, CmdLine, CmdShow
local msg:MSG
mov eax, [DefWindowProc]
mov [pWndClass.lpfnWndProc], eax
mov [pWndClass.lpszClassName], szName
invoke RegisterClass, pWndClass
invoke CreateWindowEx, WS_EX_LEFT, szName, szName, WS_OVERLAPPEDWINDOW or WS_VISIBLE, 0, 0, 320, 240, NULL, NULL, NULL, NULL
@@:
lea eax, [msg]
invoke GetMessage, eax, NULL, 0, 0
cmp eax, 0
je @f
lea eax, [msg]
invoke DispatchMessage, eax
jmp @b
@@:
mov eax, [msg.wParam]
ret
endp
start:
invoke GetModuleHandle, NULL
mov [hInstance], eax
invoke GetCommandLine
mov [pCommand], eax
stdcall WinMain, [hInstance], NULL, [pCommand], SW_SHOWNORMAL
invoke ExitProcess, eax
完成