程式語言 - ObjAsm - Dialog - Handle Event



參考資訊:
https://github.com/ObjAsm
https://objasm.x10host.com/index.htm

main.asm

%include @Environ(OBJASM_PATH)\Code\Macros\Model.inc
SysSetup OOP, WIN32, ANSI_STRING
     
MakeObjects Primer
  
    .const   
Object MyApp, , Primer
    RedefineMethod Init
    StaticMethod Run
    StaticMethod WndProc, UINT, WPARAM, LPARAM

    DefineVariable hWnd, HWND, 0
    DefineVariable pDefWndProc, DWORD, 0
ObjectEnd

    .data
MyObj dd 0

    .code
Method MyApp.Init, uses esi
    SetObject esi
    invoke CreateWindowEx, WS_EX_LEFT, WC_DIALOG, $OfsCStr("main"), 
        WS_OVERLAPPEDWINDOW or WS_VISIBLE, 0, 0, 300, 300, NULL, NULL, NULL, pSelf
    m2m [esi].hWnd, eax
 
    invoke SetWindowLong, [esi].hWnd, GWL_WNDPROC, $MethodAddr(MyApp.WndProc)
    m2m [esi].pDefWndProc, eax
    m2m MyObj, pSelf
MethodEnd

Method MyApp.Run, uses esi
    local msg:MSG
 
@@:
    invoke GetMessage, addr msg, NULL, 0, 0
    cmp eax, 0
    je @f
    invoke DispatchMessage, addr msg
    jmp @b
@@:
    mov eax, msg.wParam
MethodEnd

Method MyApp.WndProc, uses esi, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    mov esi, MyObj
    assume esi:ptr $Obj(MyApp)

    .if uMsg == WM_CLOSE
        invoke DestroyWindow, [esi].hWnd
    .elseif uMsg == WM_DESTROY
        invoke PostQuitMessage, 0
    .else
        invoke CallWindowProc, [esi].pDefWndProc, [esi].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

完成