Jump to content
  • Advertisement
Sign in to follow this  
jchmack

Locking the position of the win32 mouse

This topic is 3813 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!