Fixed bug 3847 - Hit Test x coordinate wrong on secondary monitor

Robert Turner

SDL_windowsevents.c contains code to retrieve the x and y coordinate for a requested hit test. It does this as follows:

    POINT winpoint = { (int) LOWORD(lParam), (int) HIWORD(lParam) };

LOWORD(lParam) does not correctly mask off high bits that are set if the point is on a second (or third, etc.) monitor. This effectively offsets the x-coordinate by a large value.

MSDN documentation suggests that LOWORD() and HIWORD() are the wrong macros for the task, instead suggesting we should be doing something like the following:

    POINT winpoint = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };

Testing this change on my Windows 10 machine with 2 monitors gives the correct results.
Sam Lantinga 2017-09-26 15:07:35 -07:00
parent fb071a4cd9
commit 54685787ca
1 changed files with 1 additions and 1 deletions

View File

@ -961,7 +961,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
SDL_Window *window = data->window;
if (window->hit_test) {
POINT winpoint = { (int) LOWORD(lParam), (int) HIWORD(lParam) };
POINT winpoint = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
if (ScreenToClient(hwnd, &winpoint)) {
const SDL_Point point = { (int) winpoint.x, (int) winpoint.y };
const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);