c - Windows API 在 GetStdHandle() 中不起作用

标签 c winapi

我更新了我的代码,但光标仍然可见。帮帮我,谢谢。 (我是 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_INFOdwSize 成员:

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/

相关文章:

c - libcurl:使用 WriteMemoryCallback 时 curl_easy_perform 上的段错误

c - 使用 memcpy() 后断言失败

c++ - 等待 Win32 应用程序中的特定键

delphi - Delphi 中其他进程的 StackWalk?

c++ - 如何在c/c++中已知列的情况下一次按行动态分配二维数组

c - 在 C 中将字符追加到字符数组

c - 从 pthread C 调用时 read() 不起作用

c++ - 线程安全和 AfxMessageBox

c# - 如何用一种颜色绘制一个基本字形,并用另一种颜色绘制其附加的变音符号?

c - RegQueryValue 失败但 RegQueryValueEx 返回一个值