Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Wrong mouse coordinates

The coordinates recovered from the mouse's callback are wrong.

For example, with a window of 640x480 pixels, if i click on the bottom right corner the recovered coordinates are x:645 and y:507 instead of x:639 et y:479.

I looked into the code (window_w32.cpp line 1484):

pt.x = LOWORD( lParam );
pt.y = HIWORD( lParam );

GetClientRect( window->hwnd, &rect );
icvGetBitmapData( window, &size, 0, 0 );

window->on_mouse( event, pt.x*size.cx/MAX(rect.right - rect.left,1),
                         pt.y*size.cy/MAX(rect.bottom - rect.top,1), flags,
                         window->on_mouse_param );

And i'm wondering why do not simply do that:

POINT point;
GetCursorPos(&point);
ScreenToClient(window->hwnd, &point);
window->on_mouse( event, point.x, point.y, flags, window->on_mouse_param );

BR.

Wrong mouse coordinates

Hi,

The coordinates recovered from the mouse's callback are wrong.

For example, with a window of 640x480 pixels, if i click on the bottom right corner the recovered coordinates are x:645 and y:507 instead of x:639 et y:479.

I looked into the code (window_w32.cpp line 1484):

pt.x = LOWORD( lParam );
pt.y = HIWORD( lParam );

GetClientRect( window->hwnd, &rect );
icvGetBitmapData( window, &size, 0, 0 );

window->on_mouse( event, pt.x*size.cx/MAX(rect.right - rect.left,1),
                         pt.y*size.cy/MAX(rect.bottom - rect.top,1), flags,
                         window->on_mouse_param );

And i'm wondering why do not simply do that:

POINT point;
GetCursorPos(&point);
ScreenToClient(window->hwnd, &point);
window->on_mouse( event, point.x, point.y, flags, window->on_mouse_param );

BR.

Wrong mouse coordinates

Hi,

The coordinates recovered from the mouse's callback are wrong.

For example, with a window of 640x480 pixels, if i click on the bottom right corner the recovered coordinates are x:645 and y:507 instead of x:639 et y:479.

I looked into the code (window_w32.cpp line 1484):

pt.x = LOWORD( lParam );
pt.y = HIWORD( lParam );

GetClientRect( window->hwnd, &rect );
icvGetBitmapData( window, &size, 0, 0 );

window->on_mouse( event, pt.x*size.cx/MAX(rect.right - rect.left,1),
                         pt.y*size.cy/MAX(rect.bottom - rect.top,1), flags,
                         window->on_mouse_param );

And i'm wondering why do not simply do that:

POINT point;
GetCursorPos(&point);
ScreenToClient(window->hwnd, &point);
window->on_mouse( event, point.x, point.y, flags, window->on_mouse_param );

or:

pt.x = LOWORD( lParam );
pt.y = HIWORD( lParam );

window->on_mouse( event, pt.x, pt.y, flags, window->on_mouse_param );

Is there something i missed? BR.