Any code that uses Lo()and Hi()incorrect, because these functions return the bytes of low and high-order a Word.
The MSDN documentation reports the following:
Use the following code to get information in the wParam parameter:
fwKeys = GET_KEYSTATE_WPARAM (wParam);
fwButton = GET_XBUTTON_WPARAM (wParam);
These macros are defined in the header files as:
#define GET_KEYSTATE_WPARAM(wParam) (LOWORD(wParam))
#define GET_XBUTTON_WPARAM(wParam) (HIWORD(wParam))
In turn, LOWORDthey are HIWORDdefined as follows:
#define LOWORD(_dw) ((WORD)(((DWORD_PTR)(_dw)) & 0xffff))
#define HIWORD(_dw) ((WORD)((((DWORD_PTR)(_dw)) >> 16) & 0xffff))
These macros are designed to perform the correct task when compiling into 32-bit and 64-bit code.
In Delphi, a block Windowscontains translations LOWORDand HIWORDthat perform the same tasks, although they are implemented somewhat differently. Therefore, I would perform the following functions:
function GET_KEYSTATE_WPARAM(wParam: WPARAM): Word; inline;
function GET_XBUTTON_WPARAM(wParam: WPARAM): Word; inline;
....
function GET_KEYSTATE_WPARAM(wParam: WPARAM): Word;
begin
Result := LoWord(wParam);
end;
function GET_XBUTTON_WPARAM(wParam: WPARAM): Word;
begin
Result := HiWord(wParam);
end;
source
share