我知道这可能听起来是一个重复的问题,但相信我不是。
我已经提到这个问题 ,但没有太大的帮助,因为我正在尝试使用console application
,而回答者自己却告诉他不知道ShowCursor(FALSE)不能用于控制台应用程序的原因。
这个线程也没有帮助我。
这是我尝试的事情:
使用ShowCursor():
while(ShowCursor(false)>=0); //did not work
我首先怀疑是因为msdn中的这个语句: When Windows starts up, it checks if you have a mouse. If so, then the cursor show count is initialized to zero; otherwise, it is initialized to negative one
When Windows starts up, it checks if you have a mouse. If so, then the cursor show count is initialized to zero; otherwise, it is initialized to negative one
When Windows starts up, it checks if you have a mouse. If so, then the cursor show count is initialized to zero; otherwise, it is initialized to negative one
我想也许在最新的窗口中,它不能识别连接的鼠标或触控板作为安装的鼠标,也许这就是为什么它不工作。 以下代码显示不是这种情况:
void UsingShowCursor() { CURSORINFO info; info.cbSize = sizeof(CURSORINFO); cout << ShowCursor(FALSE); cout << ShowCursor(FALSE); cout << ShowCursor(FALSE); GetCursorInfo( &info ); //info.flags is CURSOR_SHOWING }
因为我得到-1,-2,-3 这意味着最初的显示光标计数显然是0,它确定了安装的鼠标。
还有一点需要注意的是, GetCursorInfo()
也告诉游标正在显示。
使用SetCursor()
void UsingSetCursor() { HCURSOR prev = SetCursor(NULL); int i = 0; while(i++<10) { cout<<i<<endl; Sleep(1000); } if( SetCursor(prev) == NULL ) //check if the previos cursor was NULL cout<<"cursor was hidden and shown after 10 secs\n"; }
也不行。 这也没有工作:
SetCursor(LoadCursor(NULL, NULL));
编辑:
使用LoadImage
也没有工作。
void UsingLoadImage() { // Save a copy of the default cursor HANDLE arrowHandle = LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW), IMAGE_CURSOR, 0, 0, LR_SHARED); HCURSOR hcArrow = CopyCursor(arrowHandle); HCURSOR noCursorHandle = (HCURSOR)LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR,1,1,LR_SHARED); //a single pixel thick cursor so that it wont be visible HCURSOR noCursor = CopyCursor(noCursorHandle); SetSystemCursor(noCursor, OCR_NORMAL); int i =0 ; while(i++<10) { cout<<i<<endl; Sleep(1000); } //revert to previous cursor SetSystemCursor(hcArrow, OCR_NORMAL); DestroyCursor(hcArrow); }
什么可能是错误? 我们如何隐藏控制台应用程序的鼠标?
你可以使用LoadImage()来实现你想要的。 这里是问题中引用的函数UsingLoadImage()的修改后的工作版本。 您必须将游标资源文件包含到Visual Studio项目中。 从这里下载光标或创建自己的光标。
Resource Files->Add->Existng Item
并浏览到nocursor.cur文件。
void UsingLoadImage() { // Save a copy of the default cursor HANDLE arrowHandle = LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW), IMAGE_CURSOR, 0, 0, LR_SHARED); HCURSOR hcArrow = CopyCursor(arrowHandle); // Set the cursor to a transparent one to emulate no cursor HANDLE noCursorHandle = LoadImage(GetmoduleeHandle(NULL), L"nocursor.cur", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE); //worked //HANDLE noCursorHandle = LoadCursorFromFile(L"nocursor.cur"); //this also worked HCURSOR noCursor = CopyCursor(noCursorHandle); SetSystemCursor(noCursor, OCR_NORMAL); int i =0 ; while(i++<10) { cout<<i<<endl; Sleep(1000); } SetSystemCursor(hcArrow, OCR_NORMAL); DestroyCursor(hcArrow); }
这将取代正常的箭头光标与透明的一个。 如果你想隐藏所有其他光标,如文本,加载,手游标等,你必须单独隐藏它们。 如果你不想这样做,那么你应该选择退出控制台应用程序,正如许多评论者指出的那样。
希望这可以帮助。