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);
}
我想在控制台中隐藏光标,但是失败了。
此处列出了GCC-mingw32的报告:
error: request for member 'bVisible' in something not a structure or union
error: incompatible type for argument 2 of 'SetConsoleCursorInfo'
有人可以帮助我吗?
感谢。
答案 0 :(得分:4)
#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;
}
答案 1 :(得分:0)
您必须为CONSOLE_CURSOR_INFO结构提供大小。否则它不起作用。
CONSOLE_CURSOR_INFO CURSOR;
CURSOR.bVisible = FALSE;
CURSOR.dwSize = 1; / 这是你遗漏的东西 /
SetConsoleCursorInfo(StdHandle,&amp; CURSOR);