When I handle WM_MOUSEMOVE in my window prodedure, HIWORD(lParam) and LOWORD(lParam) are both a little off. It's returning a point that is slightly to the left and slightly above where my cursor actually is...
What's really weird is that as I move the cursor closer to the top left of the client area of the window, the amout that the position I'm given differs from the actual cursor position gets smaller...

At first I thought it was because it was in screen coordinates and I needed to call ScreenToClient to convert it to client space coordinates, but this was not the case.

This is how I handle it, I don't change the coords it gives me anywhere.

case WM_MOUSEMOVE:
    input->HandleInput (LOWORD(lParam), HIWORD(lParam));
    break;

Recommended Answers

All 9 Replies

The position comes in as pixels.
ScreenToClient does shifting only, not scaling.

What you describe looks like some SCALING of the coordinates.
Maybe you take a closer look at your code for any scaling operations that might be in effect?

I wouldn't know what to send you because 1. it's quite a large code base, and 2. i'm not doing any scaling anywhere, this is the only part that i access these co-ordinates, i don't change them anywhere.
I've also stepped through each line of code from where I get the coordinates to where I use them and they are the same the whole way through.

Interesting. Try to take a rough estimate of the factor of being off: Make the window a certain number of pixels wide and high and point the mouse to the upper left and then to the lower right corner. What does it say? What is the factor of the deviation in those positions?

Ok, I figured out that around the center of the screen on the y axis, the y coordinate is 20 pixels down from where it should be, and the x coordinate seems fine

Well then the assumtion about scaling should be proven false.
The offset in y should be the title bar. There is a possibility to get its hight, but at the drop of a hat i can't remember ist... Something with "getmetrics" or so...

GetSystemMetrics

see: http://msdn.microsoft.com/en-us/library/ms724385%28v=vs.85%29

...But: ScreenToClient was another correct approach. There must be a function calculating the mouse position within the pure client area instead of in the whole window, that takes things like title bar size and border size into account...

...With WM_NCCALCSIZE for example you can get this offset: http://msdn.microsoft.com/en-us/library/ms632634%28v=vs.85%29

I think what you're refering to GetSystemMetrics, I'll give it a try

It ended up being me forgetting to resize my OpenGL viewport when the window was resized.. doh!
Thanks for your help! :)

Well, Microsoft is a bit peculiar concerning the term "client area": Sometimes they mean the window in its entirety (with border and title bar included), sometimes only the client area within the border and under the title bar.

It's not always clear at first view and their documentation is not the best of the world...
But of course we are flexible... :o)

Yeah their doccos are strange sometimes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.