Cursor won't hide!


My problem is funny and rather simple. It goes like this… When I am debugging my application the mouse pointer hides when I start my program. After building a realase version and running it the cursor IS visible. Have you ever noticed something like that? I used mainly NeHe Tutorials to create a window. I tried ShowCursor(false). Any hints?


I assume you are talking about Win32.

When you lookup the spec for ShowCursor() you will find this:


The ShowCursor function displays or hides the cursor.

int ShowCursor(BOOL bShow// cursor visibility);


[in] Specifies whether the internal display counter is to be incremented or decremented. If bShow is TRUE, the display count is incremented by one. If bShow is FALSE, the display count is decremented by one.

Return Values:

The return value specifies the new display counter.


This function sets an internal display counter that determines whether the cursor should be displayed. The cursor is displayed only if the display count is greater than or equal to 0. If a mouse is installed, the initial display count is 0. If no mouse is installed, the display count is –1.

So check the result from the call, I bed it’s greater then zero.

That’s it … lol

Well thanx but I know how to use it. I noticed that the cursor is visible if I am moving the mouse while program is setting up. If I try to run it by keyboard the cursor isn’t visible. Funny thing, isn’t it?

The question isnt how to use it, but to understand how it works.

And frankly, you dont seem to understand how it works.

Ok but how would you explain that the cursor isn’t visible when I run the program from a compiler but it IS when I am executing the exe file form my OS (Win98)?

This code solved all my cursor problems:

int the_win32api_sucks=ShowCursor(false);
while (the_win32api_sucks>=0) the_win32api_sucks=ShowCursor(false);

The reason why you see different results is explained in the manual for the function.

Either do what Zeckensack said, or you could use SetCursor(NULL) to set the cursor to a blank cursor while it is in your client area (read the manual for that function as it has some drawbacks too).

Anyway this is a OpenGL forum after all.

Thanks guys!

PS. I suppose you can be a bit more polite 1234!

SetClassLong(hWnd, GCL_HCURSOR, (LONG) LoadCursor (NULL, IDC_ARROW));
SetCursor (LoadCursor (NULL, IDC_ARROW));

This forces, that you get the desired cursor. Do this once, and you don´t have to bother anymore.
This code will give you the standard cursor, but if you use a NULL somewhere instead, than your cursor should get hidden, if i remember it right.


Originally posted by [—]:
PS. I suppose you can be a bit more polite 1234!

Yeah I suppose I could but that would break my granddad’s heart…

If you want to use SetCursor(NULL) make sure the windows class cursor is also set to NULL, otherwise Windows will restore the cursor to the one registered in the window class as soon as you move the mouse.

In case you use the MFC use this:

SetClassLong(GetSafeHwnd(), GCL_HCURSOR, NULL);

If you dont use MFC you have to replace the GetSafeHwnd() call with your HWND handle.

The drawback using this approach is, that as soon as the mouse leaves your window the old cursor gets restored by the system and will also become visible in your window again.

I would use Zeckensack’s approach if I where you.

Now was that polite enough?

Yeah. That was very nice. Thank you.

Ehh… I’ve tried what you suggested but it seems that problem isn’t about the mouse really. Pointer is still visible - but if I click a mouse button it disappears. Sorry for my stupid questions. I think it is something rather simple to solve and I really appreciate your help.