C++ – PeekMessage() Resetting the Mouse Cursor

ccursorpeekmessage

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.

Best Answer

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.