程式語言 - ObjAsm - x64 - Dialog - Handle 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
     
Object MyApp, , Primer
    RedefineMethod Init
    StaticMethod Run
    StaticMethod WndProc, UINT, WPARAM, LPARAM
   
    DefineVariable hWnd, HWND, 0
    DefineVariable pDefWndProc, POINTER, 0
ObjectEnd
   
Method MyApp.Init, uses rsi
    SetObject rsi
 
    invoke CreateWindowEx, WS_EX_LEFT, WC_DIALOG, $OfsCStr("main"), WS_OVERLAPPEDWINDOW or WS_VISIBLE, 0, 0, 320, 240, NULL, NULL, NULL, pSelf
    mov [rsi].hWnd, rax
    
    invoke SetWindowLongPtr, [rsi].hWnd, GWL_WNDPROC, $MethodAddr(MyApp.WndProc)
    mov [rsi].pDefWndProc, rax
MethodEnd
   
Method MyApp.Run, uses rsi
    local msg:MSG
    
@@:
    invoke GetMessage, addr msg, NULL, 0, 0
    cmp rax, 0
    je @f
    invoke DispatchMessage, addr msg
    jmp @b
 
@@:
    mov rax, msg.wParam
MethodEnd
   
Method MyApp.WndProc, uses rsi, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    assume rsi:ptr $Obj(MyApp)
    mov rsi, offset $ObjTmpl(MyApp)
 
    .if uMsg == WM_CLOSE
        invoke DestroyWindow, [rsi].hWnd
    .elseif uMsg == WM_DESTROY
        invoke PostQuitMessage, 0
    .else
        invoke CallWindowProc, [rsi].pDefWndProc, [rsi].hWnd, uMsg, wParam, lParam
    .endif
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

完成