0
votes

I need to hide cursor when left and right buttons are both pressed. It turns out the my code is working as expected except for minor glitch with mouse move.

When I call ShowCursor(FALSE) cursor becomes hidden as expected. After that when I call ShowCursor(TRUE) cursor is not appearing again until next mouse move. My opinion - its just is not drawn until mouse event occurs. Is there a way to force cursor to be redrawn?

Code:

void SG::CursorManager::hideCursor(void) {
    while(ShowCursor(FALSE) >= 0);
}

void SG::CursorManager::showCursor(void) {
    while(ShowCursor(TRUE) <= 0);
}
1

1 Answers

6
votes

If I understand correctly how cursor work in Windows, you have to call SetCursor(IDC_...) to make the cursor visible immediately.

The thing is that the cursor usually set from the window beneath, as a response to message WM_SETCURSOR. The idea of ShowCursor() is that it disables/enables the WM_SETCURSOR message. When disabling the cursr it also does SetCursor(NULL) so that the cursor dissapears. But when enabling the cursor it cannot call SetCursor(IDC_...) because it does not know which cursor should be shown. So it waits until the next WM_SETCURSOR is generated, that it until the mouse is moved.