- 1 year ago
Coordinates of WM_POINTERDOWN and WM_LBUTTONDOWN Differ
The difference in coordinates between WM_POINTERDOWN
and WM_LBUTTONDOWN
messages can occur due to different coordinate spaces and handling mechanisms associated with touch and mouse input in Windows.
Coordinate spaces: Touch and mouse inputs have different coordinate spaces in Windows. Touch inputs are reported in physical screen coordinates, whereas mouse inputs are typically reported in client coordinates relative to the window.
Translation and scaling: Windows automatically performs translation and scaling of touch coordinates to match the current DPI scaling and display orientation. This ensures that touch inputs are accurate and consistent across different devices and screen resolutions.
Pointer input handling: Windows supports multiple simultaneous pointer inputs, such as touch, stylus, and mouse. Each input type may have its own input handler, and these handlers may apply different transformations or processing to the input coordinates.
To align the coordinates between WM_POINTERDOWN
and WM_LBUTTONDOWN
messages, you can use the MapWindowPoints
function to convert the touch coordinates to client coordinates:
cpp// Handling WM_POINTERDOWN message
case WM_POINTERDOWN:
{
// Get touch input information
POINTER_INFO pointerInfo;
if (GetPointerInfo(GET_POINTERID_WPARAM(wParam), &pointerInfo))
{
// Convert touch coordinates to client coordinates
POINT clientPoint = pointerInfo.ptPixelLocation;
ScreenToClient(hWnd, &clientPoint);
// Use the client coordinates for further processing
// ...
}
}
break;
In the above code snippet, the ScreenToClient
function is used to convert the touch coordinates (pointerInfo.ptPixelLocation
) from screen coordinates to client coordinates relative to the window (hWnd
).
By applying this conversion, you can align the coordinates received from WM_POINTERDOWN
with those received from WM_LBUTTONDOWN
messages, making them consistent for your application's further processing.