Steward
分享是一種喜悅、更是一種幸福
程式語言 - ObjAsm - x64 - Keyboard Event
參考資訊:
https://github.com/ObjAsm
https://objasm.x10host.com/index.htm
main.S
%include @Environ(OBJASM_PATH)/Code/Macros/Model.inc
SysSetup OOP, WIN64, ANSI_STRING
MakeObjects Primer, Stream, WinPrimer, Window, WinApp, SdiApp
Object MyApp, , SdiApp
RedefineMethod Init
VirtualEvent OnKeyDown, WM_KEYDOWN
VirtualEvent OnPaint, WM_PAINT
DefineVariable wndClass, WNDCLASSEX, { 0 }
ObjectEnd
Method MyApp.Init, uses rsi
SetObject rsi
ACall rsi.Init
mov [rsi].wndClass.cbSize, sizeof WNDCLASSEX
m2m [rsi].wndClass.lpfnWndProc, $MethodAddr(MyApp.WndProc), xdx
c2m [rsi].wndClass.lpszClassName, $OfsCStr("main"), xdx
invoke RegisterClassEx, addr [rsi].wndClass
invoke CreateWindowEx, WS_EX_LEFT, $OfsCStr("main"), $OfsCStr("main"), WS_OVERLAPPEDWINDOW or WS_VISIBLE, 0, 0, 320, 240, NULL, NULL, NULL, pSelf
mov [rsi].hWnd, rax
MethodEnd
Method MyApp.OnPaint, uses rsi, wParam:WPARAM, lParam:LPARAM
local hDC:HDC
local PS:PAINTSTRUCT
SetObject rsi
mov hDC, $invoke(BeginPaint, [rsi].hWnd, addr PS)
invoke EndPaint, [rsi].hWnd, addr PS
MethodEnd
Method MyApp.OnKeyDown, uses rsi, wParam:WPARAM, lParam:LPARAM
local buf[255]:BYTE
SetObject rsi
invoke wsprintf, addr buf, $OfsCStr("Key: %d"), wParam
invoke SetWindowText, [rsi].hWnd, addr buf
invoke DefWindowProc, [rsi].hWnd, WM_KEYDOWN, wParam, lParam
MethodEnd
start proc
SysInit
OCall $ObjTmpl(MyApp)::MyApp.Init
OCall $ObjTmpl(MyApp)::MyApp.Run
OCall $ObjTmpl(MyApp)::MyApp.Done
SysDone
invoke ExitProcess, 0
start endp
end
完成