• Advertisement
Sign in to follow this  

Hiding the cursor not working

This topic is 3729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Before I start, yes, I know, this has been discussed many many times before. I have read so many threads about this that I have lost count. But they didn't help. My game uses D3D8 and DInput. I'm trying to hide the cursor when the game is running, but nothing works. I create the mouse device with GUID_SysMouse and DISCL_FOREGROUND | DISCL_EXCLUSIVE. The docs says that if you create the mouse device with GUID_SysMouse and exclusive mode the cursor is removed from the screen. But that doesn't happen. I have the same problem in windowed and fullscreen. In windowed if I move the cursor outside the game's window and click, it's my game that responds. The cursor can not affect anything else on screen. I tried using ShowCursor(FALSE), but nothing. Before you ask, yes I know that it uses an internal counter. I have not used SetCursor() anywhere and I'm sure I don't call ShowCursor() more than once at startup and once at exit. I have check the return value from ShowCursor() which is the new value of the display counter and I got some strange results. To be extra sure what is happening I tried calling the ShowCursor(FALSE) three times at startup and ShowCursor(TRUE) three times at exit and checked the return value. This is the result: Startup: ShowCursor(FALSE): dispCount:-1 ShowCursor(FALSE): dispCount:-2 ShowCursor(FALSE): dispCount:-3 These values are correct as the display counter should start at 0. Though the cursor is not hidden after these calls. Exit: ShowCursor(TRUE): dispCount:-4 ShowCursor(TRUE): dispCount:-3 ShowCursor(TRUE): dispCount:-2 Strange that somehow the display counter is now on -4. I don't understand how that can be. I only use ShowCursor() in two places in the whole source code. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Oh, forget about the strange return values from ShowCursor, that's my fault. I called the functions in this order:

ShowCursor(FALSE);
ShowCursor(FALSE);
ShowCursor(FALSE);
mouse.Acquire();

ShowCursor(TRUE);
ShowCursor(TRUE);
ShowCursor(TRUE);
mouse.Unacquire();

when changed so that mouse.Unacquire() comes before ShowCursor(TRUE), the values makes sense. -1, -2, -3 then -2, -1, 0.

It seems DInput also calls ShowCursor() as that explains my strange return values.

But the problem remains as the cursor is still always visible.

Share this post


Link to post
Share on other sites
SetCursor(NULL) in WM_SETCURSOR works, but that seems (to me) like a workaround and not a correct solution. Not the solution that I'm looking for anyway. Also, doing it with SetCursor(NULL) will be a major hassle for me.
I know it should be possible without the use of SetCursor() as I have managed to do it before. But that was a long time ago and I don't remeber how I did it and can't find that code. I probably don't remember because I didn't have any problems with it back then.

Share this post


Link to post
Share on other sites
I have finally solved this problem. I found some info on a website about SetCursor() not working from a secondary thread. And as my game is multithreaded and all the game stuff is on a secondary thread, I thought, maybe that holds true for ShowCursor() aswell.

That it did. When calling ShowCursor() from the main thread (where the message pump is located) it works fine. No need for SetCursor(NULL).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement