Sign in to follow this  

Locking the position of the win32 mouse

This topic is 3594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way i can restrict the position of the win32 mouse to the same spot? I have a basic app. The user can drag the screen underneath the mouse. If the mouse button is up when the user moves his mouse the app moves the mouse. But if the mouse button is down when the user moves his mouse the app SHOULD keep the mouse in the same spot but scroll the background. Thanks for any help in advance =).

Share this post


Link to post
Share on other sites
Don't know if there is a single command that will do this, but, you could get the position of the mouse cursor at the time of the click, and then every frame after set its position to that. I know its possible, just don't ask me the specific commands.

Share this post


Link to post
Share on other sites
Thank you for the reply but it seems that if i do this with SetCursorPos(CurX,CurY) each frame like you suggested the mouse will still jump around because it is trying to move each frame but is then jerked back into position. Although Functionally this works i would like it a lot more if i could avoid this jerking.

Share this post


Link to post
Share on other sites
You could consider hiding the cursor when you have the mouse button down and are dragging, then re-show the cursor when the mouse button is released.

I believe the Win32 calls to do this are simple.

ShowCursor(false) to hide the mouse.
ShowCursor(true) to show it.

This should only cause the cursor to be hidden when it is actually positioned over your window. Of course, when you reset the position back to your window it will keep it there.

If you absolutely must have the cursor stay displayed, I think you can use GetCursorInfo to get the cursor information then use the handle returned to draw the image manually to the screen.

Share this post


Link to post
Share on other sites

This topic is 3594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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