views:

176

answers:

1

Im currently messing around with changing the mouse cursor within a game like C++ application for Windows XP.

To change the cursor I am using SetCursor() and passing in the desired cursor, which is working. However during the while loop in which PeekMessage() is called the cursor keep getting reset back to the default arrow.

This is the offending loop:

MSG  msg;
while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
 TranslateMessage( &msg );
 DispatchMessage( &msg );
}

While debugging I found that the cursor changed during the call to PeekMessage() after which msg.message == 0x200, which should make the message one of these:

WM_MOUSEFIRST = 0x200
WM_MOUSEMOVE = 0x200

I haven't been able to find any information on why this is happening, and have no experience with windows messages.

Thanks.

Edit:

According to here the system redraws the class cursor everytime the mouse moves, effectively setting it back to the default cursor. With this in mind i added this to the window message callback function:

case WM_SETCURSOR:
 return 0;

problem solved.

A: 

How did you debug that? Unless you use SoftIce or some other application which doesn't share the windows mouse pointer, it would be hard to isolate the debugger from the application.

wallyk
I was only using the keyboard for debugging. The mouse remained over the application window. So i could watch and see when it changed while stepping through the code.
0xC0DEFACE
I don't think that is reliable. The debugger is still influencing the pointer. What happens if you run the application without debugging? Does it not work then?
wallyk
It still happens. if I `system( "pause" )`the application after the message loop I can see that the cursor has changed, so whilst the particular message could be incorrect, it still must be happening in there somewhere.
0xC0DEFACE
Are you following the rules for managing the cursor shape? See http://msdn.microsoft.com/en-us/library/ms648393%28VS.85%29.aspx especially for changing it back to whatever it was when you're done.
wallyk
heh, nice link. although i had already read that page this part now stood out: "If the class cursor is not NULL, the system restores the class cursor each time the mouse is moved" which exactly what is happening. Thanks for that!
0xC0DEFACE
Your comment led to the problem being solved. Thanks for your help!
0xC0DEFACE
You're welcome.
wallyk