0

I renew my code, but the cursor was still visible. Help me, Thanks. (I am a newbie in C and WinAPI)

#define WINVER 0x0500
#include<windows.h>

int main() 
{
 //Get a STD OUTPUT handle
 HWND StdHandle = GetStdHandle(STD_OUTPUT_HANDLE);

 //Set cursor invisible
 CONSOLE_CURSOR_INFO CURSOR;
 CURSOR.bVisible = FALSE;
 SetConsoleCursorInfo(StdHandle, &CURSOR);
 system ("pause>nul");
 return 0;
}
1
  • Set all of the members, add CURSOR.dwSize = 1; And never skip error checking, SetConsoleCursorInfo() returns a BOOL. At least assert it. Commented Nov 16, 2013 at 19:02

1 Answer 1

2

You need to initialise the dwSize member of CONSOLE_CURSOR_INFO:

CONSOLE_CURSOR_INFO CURSOR;
CURSOR.dwSize = 1;
CURSOR.bVisible = FALSE;

From the docs for SetConsoleCursorInfo:

The dwSize member of the CONSOLE_CURSOR_INFO structure specifies the percentage of a character cell that is filled by the cursor. If this member is less than 1 or greater than 100, SetConsoleCursorInfo fails.

Note also from the same page

Return value

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Checking the return value would have helped you figure out what was going wrong.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.