Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a convenience function in win32 (windows.h) that would convert lParam to POINT?

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)?

like image 654
bodacydo Avatar asked Aug 07 '13 17:08

bodacydo


1 Answers

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 MAKEPOINTS macro to obtain a POINTS structure from the return value. You can also use the GET_X_LPARAM or GET_Y_LPARAM macro to extract the x- or y-coordinate.

Important Do not use the LOWORD or HIWORD macros 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.

like image 55
Remy Lebeau Avatar answered Oct 06 '22 01:10

Remy Lebeau