Steward
分享是一種喜悅、更是一種幸福
程式語言 - Wine - Assembly (ARM 32) - Single Document Interface (SDI) - Handle Event
參考資訊:
http://www.winprog.org/tutorial/
http://winapi.freetechsecrets.com/win32/
https://github.com/gammasoft71/Examples_Win32
http://masm32.com/board/index.php?topic=3584.0
https://learn.microsoft.com/en-us/windows/win32/winmsg/window-styles
當視窗有事件需要被處理時,系統會透過呼叫註冊的Callback副程式來處理,而這個Callback副程式就是在註冊Class時,設定給lpfnWndProc的事件處理副程式,因此,當這個事件處理副程式被呼叫時,可以處理自己感興趣的事件,而其餘事件則交給系統處理(透過呼叫DefWindowProc()),需要注意的是,例如:WM_CLOSE,就必須由該視窗自己處理,因為系統無法知道還有哪些額外的資源需要被釋放掉
main.S
.include "/opt/wadk/wine/include/windows.inc"
.data
hWin: .skip 4
szMsg: .skip 28
szAppName: .asciz "main"
pDefWndProc: .skip 4
wndClass:
.space 4 @style
.space 4 @lpfnWndProc
.space 4 @cbClsExtra
.space 4 @cbWndExtra
.space 4 @hInstance
.space 4 @hIcon
.space 4 @hCursor
.space 4 @hbrBackground
.space 4 @lpszMenuName
.space 4 @lpszClassName
wndClass_end:
WNDCLASS_SIZE: .word wndClass_end - wndClass
.balign 4
.text
WndProc:
push { lr }
cmp r1, #WM_CLOSE
beq 0f
cmp r1, #WM_DESTROY
beq 1f
b 2f
0:
bl DestroyWindow
mov r0, #0
b 3f
1:
mov r0, #0
bl PostQuitMessage
mov r0, #0
b 3f
2:
bl DefWindowProc
b 3f
3:
pop { pc }
WinMain:
push { lr }
ldr r0, =wndClass
ldr r1, =WndProc
str r1, [r0, #WNDCLASS.lpfnWndProc]
ldr r1, =szAppName
str r1, [r0, #WNDCLASS.lpszClassName]
bl RegisterClass
mov r3, #0
mov r2, #0
mov r1, #0
mov r0, #0
push { r0, r1, r2, r3 }
mov r3, #240
mov r2, #320
mov r1, #0
mov r0, #0
push { r0, r1, r2, r3 }
ldr r3, =WS_OVERLAPPEDWINDOW | WS_VISIBLE
ldr r2, =szAppName
ldr r1, =szAppName
mov r0, #WS_EX_LEFT
bl CreateWindowEx
add sp, sp, #32
ldr r1, =hWin
str r0, [r1]
0:
mov r3, #0
mov r2, #0
mov r1, #0
ldr r0, =szMsg
bl GetMessage
cmp r0, #0
beq 1f
ldr r0, =szMsg
bl DispatchMessage
b 0b
1:
mov r0, #0
bl ExitProcess
pop { pc }
編譯、執行
$ mywinegcc-armhf main.S -o main.exe $ myarm32 main.exe.so