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

Keyboard Event


參考資訊:
1. win32
2. masm32

WM_KEYDOWN、WM_KEYUP是一般鍵盤按鍵事件,而WM_SYSKEYDOWN、WM_SYSKEYUP則是屬於系統按鍵的事件,系統按鍵就是左上角小視窗圖案的那些按鍵命令

WM_KEYDOWN、WM_KEYUP

nVirtKey = (int) wParam; // virtual-key code
lKeyData = lParam;       // key data

WM_SYSKEYDOWN、WM_SYSKEYUP

nVirtKey = (int) wParam; // virtual-key code
lKeyData = lParam;       // key data

main.hla

program main;
  
#include("w.hhf")
#include("args.hhf")
#include("memory.hhf")
#include("strings.hhf")
  
static
    buf:         byte[255];
    hWin:        dword;
    hInstance:   dword;
    CommandLine: string;
    defWndProc:  dword;

    wsprintf: procedure(p0:dword; p1:dword; p2:dword); @stdcall; external("__imp__wsprintfA");

readonly
    fmt:       string:= "key: %d";
    szCaption: string:= "main";
 
procedure WndProc(hWnd:dword; uMsg:uns32; wParam:dword; lParam:dword); @stdcall;
begin WndProc;
    if ((uMsg == w.WM_KEYDOWN) || (uMsg == w.WM_SYSKEYDOWN)) then
        wsprintf(&buf, fmt, wParam);
        w.SetWindowText(hWnd, &buf);
        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, 0, 0, 300, 300, 0, 0, NULL, NULL);
    mov(eax, hWin);
 
    w.SetWindowLong(hWin, w.GWL_WNDPROC, &WndProc);
    mov(eax, defWndProc);
      
    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~26:將按鍵數值顯示在視窗標題

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


返回上一頁