我更新了我的代码,但光标仍然可见。帮帮我,谢谢。 (我是 C 和 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;
}
最佳答案
您需要初始化 CONSOLE_CURSOR_INFO
的 dwSize
成员:
CONSOLE_CURSOR_INFO CURSOR;
CURSOR.dwSize = 1;
CURSOR.bVisible = FALSE;
来自 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.
同样来自同一页的注释
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.
检查返回值可以帮助您找出问题所在。
关于c - Windows API 在 GetStdHandle() 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20022392/