Sign in to follow this  
Bad Ham

Issues with WM_MOUSEMOVE

Recommended Posts

Hi everyone. I'm having some issues with WM_MOUSEMOVE. As is listed in the MSDN docs, I'm using GET_X_LPARAM() and GET_Y_LPARAM() on the lParam of the message to extract the current mouse coords. However, no matter what I do, the coords returned are ALWAYS the same (for instance, the x coordinate is ALWAYS -888). If I use a combination of GetCursorPos and ScreenToClient then it will generally work. I am checking the WM_MOUSEMOVE in a function that is hooked into my window from my input class (using SetWindowsHookEx() and hooking WH_GETMESSAGE). Could that be causing the problem perhaps?

Share this post


Link to post
Share on other sites
Figures that I figure that out two minutes later when I've been puzzling for hours. Turns out I was using the lparam passed to the hook to grab the coords from, when that lparam actually contains a message structure.

Anyway, now I have a few more issues. #1, I don't seem to be able to record the mouse being outside of my window with this method. The coords stop at x=800 (on a 800x600 window). I guess you could detect outside of the window just by the coordinate being at the max (or min)?

Also, every frame I am outputting a debug message that compares GetCursorPos with what my input handler currently thinks the mouse position is. It tends to be off usually by 2, 4, or 8 pixels. Which doesn't make sense...

Share this post


Link to post
Share on other sites
The second problem there has been solved, I forgot to use clienttoscreen.

However I'm still not sure how to use a wm_mousemove message to get the mouse coords when it's not hovering over our window.

I did use SetCapture on my window already.

Share this post


Link to post
Share on other sites
Quote:
Original post by PrinceMarth
The second problem there has been solved, I forgot to use clienttoscreen.

However I'm still not sure how to use a wm_mousemove message to get the mouse coords when it's not hovering over our window.

I did use SetCapture on my window already.
SetCapture() should work. However, you won't get messages saying the mouse is outside of the screen (Since no messages are sent to tell you that). If you want to tell when the mouse goes outside the bounds of the screen, you'll need to use DirectInput or raw input.

Share this post


Link to post
Share on other sites
Ah, alright.

I guess another question then about a different issue I'm having.

My y-coordinate returned from WM_MOUSEMOVE is always 60 pixels less than the actual mouse position. I'm assuming that's due to the window bar ontop of the application, since I don't get WM_MOUSEMOVE messages while I'm over it. I could just add 60 to the value, but then that would break at different resolutions.

Is there some way to fix this?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this