Skip to main content
gamedev.net
🔒 Locked

[Winapi] Accurate mouse positionning

Started by Trillian Oct 11, 2006 at 8:08 PM 3 replies 850+ views
Original Post
Trillian
Trillian
Hello! I think I already had this problem some time ago but ah well, have it again and I don,t know what to do. The problem is that I cannot get and accurate mouse position using WM_MOUSEMOVE messages. The mouse position is accurate in the topleft window corner but doesn't follow the mouse to the bottomright corner so I notice an offset. Here's what happens with my WM_MOUSEMOVE, I know a lot of stuff that looks strange happens, because the code goes through a lot of functions that modify the point, I've summarized it here :

POINT p;
p.x = LOWORD(lparam);
p.y = HIWORD(lparam);

// I know the following is stupid, simply it happens in different parts of code
// That's the way my engine is made :P, It shouldn't do anything anyway
// And I've tryed doing it without these lines
::ClientToScreen(hwnd, &p);
::ScreenToClient(hwnd, &p); 

// Change to a lower-left origin
RECT rect;
::GetClientRect(hwnd, ▭);
p.y = rect.bottom-rect.top - p.y;

Now in my window :

1----------------2
|               f|
|                |
|                |
|                |
|                |
3----------------4
When the windows mouse is at point 3, My program has the right position. However, when the mouse is at point 2, My program has the position "f". There is an offset between the windows cursor and the position my program receives. My program has (790,573) when it should have (800,600). Hope I was clear!
Oluseyi
Oluseyi
First, convert from screen coordinates to client coordinates using ScreenToClient (or just subtract top and left of client area rectangle from y and x coordinates, respectively). Then convert from upper-left origin to lower-left origin by subtracting the y coordinate from the height of the client area.

You need both operations for a correct transformation.
Trillian
Trillian
My mouse position doesn't suffer from this kind of problem. The mouse coordinates are expressed in the good client space but the mouse position is not constantly accurate.

I've done a flash thing to show it, have a look : http://www.savefile.com/files/153835

Someone has ideas why this happens?
Endurion
Endurion
Are you mayhaps using DirectX and have a not correctly sized backbuffer? And use this backbuffer to check the mouse pos?
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.