Locking the position of the win32 mouse

Started by
4 comments, last by marius1930 16 years, 2 months ago
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 =).
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.
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.
deleted
Why don't you hide the mouse cursor when moving the background?

I think it is:

showCursor(true/false);
Someone who uses a, euhm..., delta!?
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.
BOOL ClipCursor(
const RECT *lpRect
);

This topic is closed to new replies.

Advertisement