High Level Assembly (HLA) >> Win32 API (HLA v1.x)

Set ScrollBar


參考資訊:
1. win32
2. masm32

當視窗的可視區域(如:300x300像素)小於顯示圖片大小(如:640x480像素)時,這時可以使用Windows視窗元件ScrollBar,用來做顯示位置調整的動作,ScrollBar元件有垂直和水平兩種方向並且提供視窗事件回報機制(WM_VSCROLL、WM_HSCROLL),因此,這裡的ScrollBar元件並不能夠自動幫忙做顯示位置調整的動作,取而代之的是,在收到WM_VSCROLL、WM_HSCROLL事件時,使用者必須自己決定哪些東西要顯示在視窗的可視區域上

main.hla

program main;
     
#include("w.hhf")
#include("args.hhf")
#include("memory.hhf")
#include("strings.hhf")
     
static
    hWin:        dword;
    hInstance:   dword;
    CommandLine: string;
    defWndProc:  dword;
   
readonly
    SLUP:      string:= "LINE++";
    SLDN:      string:= "LINE--";
    SPUP:      string:= "PAGE++";
    SPDN:      string:= "PAGE--";
    szCaption: string:= "main";
    
procedure WndProc(hWnd:dword; uMsg:uns32; wParam:dword; lParam:dword); @stdcall;
begin WndProc;
    if (uMsg == w.WM_VSCROLL) then
        mov(wParam, eax);
        and($ffff, eax);
        if (eax == w.SB_LINEUP) then
            w.SetWindowText(hWnd, SLUP);
        elseif (eax == w.SB_LINEDOWN) then
            w.SetWindowText(hWnd, SLDN);
        elseif (eax == w.SB_PAGEUP) then
            w.SetWindowText(hWnd, SPUP);
        elseif (eax == w.SB_PAGEDOWN) then
            w.SetWindowText(hWnd, SPDN);
        endif;
        xor(eax, eax);
    elseif (uMsg == w.WM_CLOSE) then
        w.DestroyWindow(hWnd);
        xor(eax, eax);
    elseif (uMsg == w.WM_DESTROY) then
        w.PostQuitMessage(0);
        xor(eax, eax);
    else
        w.CallWindowProc(defWndProc, hWnd, uMsg, wParam, lParam);
    endif;
end WndProc;
    
procedure WinMain(hInst:dword; hPrevInst:dword; CmdLine:string; CmdShow:dword);
var
    msg: w.MSG;
     
begin WinMain;
    w.CreateWindowEx(w.WS_EX_LEFT, w.WC_DIALOG, szCaption,
        w.WS_OVERLAPPEDWINDOW | w.WS_VISIBLE | w.WS_VSCROLL, 0, 0, 300, 300, 0, 0, NULL, NULL);
    mov(eax, hWin);
    
    w.SetWindowLong(hWin, w.GWL_WNDPROC, &WndProc);
    mov(eax, defWndProc);

    w.SetScrollRange(hWin, w.SB_VERT, 0, 100, false);
    w.SetScrollPos(hWin, w.SB_VERT, 50, true);
    forever
        w.GetMessage(msg, NULL, 0, 0);
        breakif(!eax);
     
        w.DispatchMessage(msg);
    endfor;
    mov(msg.wParam, eax);
end WinMain;
     
begin main;
    w.GetModuleHandle(NULL);
    mov(eax, hInstance);
    mov(arg.cmdLn(), CommandLine);
    
    WinMain(hInstance, NULL, CommandLine, w.SW_SHOWNORMAL);
    
    w.ExitProcess(eax);
end main;

Line 23~35:處理ScrollBar訊息並且顯示在視窗標題
Line 53:WS_VSCROLL是垂直的ScrollBar,WS_HSCROLL則是水平的ScrollBar
Line 59:設定ScrollBar最大的範圍
Line 60:設定ScrollBar目前的位置

Makefile

export WINEPREFIX=/home/user/.wine_amd64

TARGET=main
MYWINE=box86 wine

all:
	${MYWINE} hlaparse.exe -WIN32 -level=high -v -test ${TARGET}.hla
	${MYWINE} polink.exe @${TARGET}.link hlalib.lib ${TARGET}.obj /OUT:${TARGET}.exe

run:
	${MYWINE} ${TARGET}.exe

clean:
	rm -rf ${TARGET}.exe ${TARGET}.obj ${TARGET}.link

編譯、執行

$ make
$ make run


返回上一頁