Reputation: 5565
In Win32 do the co-ordinates returned by GET_X_PARAM and GET_Y_PARAM calls start from 0 or from 1? If I have a screen with resolution 640X480 then what values do I get? Are they from 0 to 639 and 0 to 479? Or 1 to 640 and 1 to 480?
extern "C" LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
Switch(message)
{
case WM_MOUSEMOVE:
iXPosition = GET_X_LPARAM(lParam);
iYPosition = GET_Y_LPARAM(lParam);
}
}
Upvotes: 0
Views: 174
Reputation: 14498
For WM_MOUSEMOVE, the coordinates are relative to the window's client area, not the screen - see MSDN. Given that, the points start at 0,0 for the top-left corner of the window's client area.
Also note that if you do use an API that returns screen-based mouse coordinates, like GetCursorPos, you can get negative values back on a multi-monitor system: 0,0 is the top-left of the primary monitor, which could have a secondary monitor set above or to the left of it; so the actual desktop could 'start' at a negative or other non-0,0 value. (GetSystemMetrics(SM_XVIRTUALSCREEN) will return the left edge, for example.)
Upvotes: 5