程式語言 - ObjAsm - Set Scrollbar



參考資訊:
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, Stream, WinPrimer, Window, WinApp, SdiApp
 
    .const
CStr szName, "main"
 
Object MyApp, , SdiApp
    RedefineMethod Init
    VirtualEvent OnVScroll, WM_VSCROLL
    VirtualEvent OnPaint, WM_PAINT

    DefineVariable wndClass, WNDCLASS, {0}
ObjectEnd
 
    .code    
Method MyApp.Init, uses esi
    SetObject esi
    ACall esi.Init
 
    m2m [esi].wndClass.hbrBackground, COLOR_WINDOW
    m2m [esi].wndClass.lpfnWndProc, $MethodAddr(MyApp.WndProc)
    m2m [esi].wndClass.lpszClassName, offset szName
    invoke RegisterClass, addr [esi].wndClass
 
    invoke CreateWindowEx, WS_EX_LEFT, offset szName, offset szName,
        WS_OVERLAPPEDWINDOW or WS_VISIBLE or WS_VSCROLL, 0, 0, 300, 300, NULL, NULL, NULL, pSelf
    m2m [esi].hWnd, eax

    invoke SetScrollRange, [esi].hWnd, SB_VERT, 0, 100, FALSE
    invoke SetScrollPos, [esi].hWnd, SB_VERT, 50, TRUE
MethodEnd
 
Method MyApp.OnPaint, uses esi, wParam:WPARAM, lParam:LPARAM
    local hDC:HDC
    local PS:PAINTSTRUCT
 
    SetObject esi
    mov hDC, $invoke(BeginPaint, [esi].hWnd, addr PS) 
    invoke EndPaint, [esi].hWnd, addr PS
MethodEnd
 
Method MyApp.OnVScroll, uses esi, wParam:WPARAM, lParam:LPARAM
    SetObject esi
    mov eax, wParam
    and eax, 0fffh
    .if eax == SB_LINEUP
        invoke SetWindowText, [esi].hWnd, $OfsCStr("LINE++")
    .elseif eax == SB_LINEDOWN
        invoke SetWindowText, [esi].hWnd, $OfsCStr("LINE--")
    .elseif eax == SB_PAGEUP
        invoke SetWindowText, [esi].hWnd, $OfsCStr("PAGE++")
    .elseif eax == SB_PAGEDOWN
        invoke SetWindowText, [esi].hWnd, $OfsCStr("PAGE--")
    .endif
    invoke DefWindowProc, [esi].hWnd, WM_VSCROLL, 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

完成