Wrong mouse coordinates [closed]

asked 2013-09-27 04:41:16 -0500

Djo1509 gravatar image

updated 2013-09-27 04:47:48 -0500

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.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2016-01-24 22:13:16.211020

Comments

imho it was a bug but fixed.

sturkmen gravatar imagesturkmen ( 2016-01-24 22:14:28 -0500 )edit