I keep doing the following:
LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
mouse.x = LOWORD(lParam);
mouse.y = HIWORD(lParam);
// ...
return 0;
}
I wonder if there is a convenience method that will convert LOWORD(lParam) and HIWORD(lParam) to a Point for me? So I could do something like mouse = ToPoint(lParam)?
Use GET_X_LPARAM() and GET_Y_LPARAM(), or MAKEPOINTS(), like the WM_MOUSEMOVE documentation says to:
Use the following code to obtain the horizontal and vertical position:
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
As noted above, the x-coordinate is in the low-order short of the return value; the y-coordinate is in the high-order short (both represent signed values because they can take negative values on systems with multiple monitors). If the return value is assigned to a variable, you can use the
MAKEPOINTSmacro to obtain aPOINTSstructure from the return value. You can also use theGET_X_LPARAMorGET_Y_LPARAMmacro to extract the x- or y-coordinate.Important Do not use the
LOWORDorHIWORDmacros to extract the x- and y- coordinates of the cursor position because these macros return incorrect results on systems with multiple monitors. Systems with multiple monitors can have negative x- and y- coordinates, and LOWORD and HIWORD treat the coordinates as unsigned quantities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With