无法在控制台中隐藏光标?

Kev*_*ong 1 c winapi mingw32

int main (void) 
{
 //Get a console handle
 HWND myconsole = GetConsoleWindow();

 struct CONSOLE_CURSOR_INFO
 {
  DWORD dwSize;
  BOOL bVisible;
 };
 struct CONSOLE_CURSOR_INFO CURSOR;

 CURSOR.bVisible = FALSE;
 SetConsoleCursorInfo(myconsole, CURSOR);
}
Run Code Online (Sandbox Code Playgroud)

我想在控制台中隐藏光标,但失败了。

此处列出了 GCC-mingw32 报告的内容:

error: request for member 'bVisible' in something not a structure or union
error: incompatible type for argument 2 of 'SetConsoleCursorInfo'
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我吗?

谢谢。

BLU*_*IXY 5

#include <windows.h>
#include <wincon.h>
#include <stdio.h>

int main (void) 
{
 //Get a console handle
 HANDLE myconsole = GetStdHandle(STD_OUTPUT_HANDLE);

/* It is already defined.
 struct CONSOLE_CURSOR_INFO
 {
  DWORD dwSize;
  BOOL bVisible;
 };
*/
 //CONSOLE_CURSOR_INFO is defined type.
 CONSOLE_CURSOR_INFO CURSOR;

 BOOL result;

 CURSOR.dwSize = 1;
 CURSOR.bVisible = FALSE;
 result=SetConsoleCursorInfo(myconsole, &CURSOR);//second argument need pointer
 if(result){//success
   printf("test print\n");
   getch();//wait
 }
 return 0;
}
Run Code Online (Sandbox Code Playgroud)

  • 考虑使用 [`#define STRICT`](http://msdn.microsoft.com/en-us/library/windows/desktop/aa383681.aspx)。它会捕获您将“HANDLE”分配给“HWND”并将“HW​​ND”传递给“HANDLE”参数的尝试。并相应地修复代码。 (2认同)