Steward
分享是一種喜悅、更是一種幸福
程式語言 - Netwide Assembler (NASM) - Win32 API - Dialog - Create Window
參考資訊:
https://masm32.com/board/index.php
https://www.nasm.us/xdoc/2.13rc9/html/nasmdoc0.html
Windows的視窗可以分成:Dialog、Single Document Interface(SDI)、Multiple Document Interface(MDI)三種類別,相較於SDI、MDI這兩類別的程式,Dialog類別是比較容易上手學習的一個類別,相當適合初學者入門學習,而Windows程式設計的精髓就是,學會其中一個類別,其餘類別都可以很容易上手,Windows控制項(如:Button、Edit)也是此類道理,比較需要注意的是,Windows視窗程式設計的核心是圍繞着事件處理(處理Message),任何的視窗設定或者溝通都是以事件導向為原則,因此,寫出一個簡單的視窗框架,將有助於了解Windows視窗程式的運作
main.asm
%include "/opt/wadk/nasm/inc/windows.inc"
section .data
szAppName DB "main",0
hInstance DD 0
pCommand DD 0
msg istruc MSG
at .hwnd, DD 0
at .message, DD 0
at .wParam, DD 0
at .lParam, DD 0
at .time, DD 0
at .pt, DD 0, 0
iend
section .text
WinMain:
enter 0, 0
push NULL
push NULL
push NULL
push NULL
push 240
push 320
push 0
push 0
push WS_OVERLAPPEDWINDOW | WS_VISIBLE
push szAppName
push WC_DIALOG
push WS_EX_LEFT
call CreateWindowEx
.loop:
push 0
push 0
push 0
push msg
call GetMessage
cmp eax, 0
je .exit
push msg
call DispatchMessage
jmp .loop
.exit:
mov eax, [msg + MSG.wParam]
leave
ret 16
_start:
push 0
call GetModuleHandle
mov [hInstance], eax
call GetCommandLine
mov [pCommand], eax
push SW_SHOWNORMAL
push DWORD [pCommand]
push 0
push DWORD [hInstance]
call WinMain
push 0
call ExitProcess
完成