Windows API: Cursor

Started by
3 comments, last by zaambu 19 years, 11 months ago
I have a problem that I assume has an obvious solution, since most commercial games deal with it. High level description: I want to capture mouse motion without being limited by cursor position. Mouse motion will control rotation in my program, and I''d like the user to be able to rotate infinitely in a particular direction without stopping. So, for example, I don''t want to have rotation stop when the cursor would normally hit the edge of the screen. My solution idea: First off, I hide the cursor using ShowCursor(FALSE). My idea was to do the following: - use SetCursor to place the cursor in the middle of the screen - on a WM_MOUSEMOVE event, find the difference in mouse position from the centre of the screen, then use SetCursor to put the cursor back in the middle This logic doesn''t actually seem to work . Is there a better way of doing this? Or is my implementation flawed? Thanks
Advertisement
Maybe you should first store the mouse position to variables and when button(rotation motion starts) is pressed, then just Set the mouse pos to thoes coords long as needed.
using direct input you can get the amount the mouse was moved since the last call of the function....its called mouse mikeys or something like that....it works even if the cursor is stopped at the edge of the screen


"A soldier is a part of the 1% of the population that keeps the other 99% free" - Lt. Colonel Todd, 1/38th Infantry, Ft. Benning, GA
Thanks for the input guys. I solved the problem.

If I reset the cursor position in the WM_MOUSEMOVE handler, I create an infinite loop of MOUSEMOVE messages that locks up the application. The solution is to not handle WM_MOUSEMOVE, and instead read and reset the mouse position just before render time (i.e. on the WM_PAINT message). This way there''s no cycle of mouse-related messages and hence no lockups.
That''s because SetCursorPos() sends another WM_MOUSEMOVE message to your program, which in turn calls SetCursorPos() again, etc. It''s an infinite recursion.

This topic is closed to new replies.

Advertisement