![](/img/trans.png)
[英]How do I display dynamic text at the mouse cursor via C++/MFC in a Win32 application
[英]How do I hide the mouse cursor in a Win32 console?
我有一個將Win32控制台設置為全屏的功能。 問題是當它進入全屏狀態時,它沒有隱藏鼠標光標。
是否全屏顯示似乎無關緊要。 當我調用ShowCursor(FALSE)時,鼠標光標仍然顯示。 如何隱藏?
就像在ShowCursor()的文檔中一樣,如果函數返回的值大於0,則光標將隱藏。如果為負數,則它將隱藏。 該值對我來說返回-2,因此在這種情況下它應該隱藏,但不是。
bool Console::setFullScreen(const bool fullScreen)
{
HWND handle;
if (fullScreen)
{
// Hide the scrollbar
showScrollBar(false);
// Set the window style
handle = GetConsoleWindow();
LONG style = GetWindowLong(handle, GWL_STYLE);
style &= ~(WS_BORDER | WS_CAPTION | WS_THICKFRAME);
SetWindowLong(handle, GWL_STYLE, style);
// Set the window to full screen in windowed mode
ShowWindow(getHandle(), SW_MAXIMIZE);
// Hide the cursor
ShowCursor(FALSE); // Fails
}
else
{
showScrollBar(true);
// Set the window style
handle = GetConsoleWindow();
LONG style = GetWindowLong(handle, GWL_STYLE);
style |= WS_BORDER;
style |= WS_CAPTION;
style |= WS_THICKFRAME;
SetWindowLong(handle, GWL_STYLE, style);
// Set the window to full screen in windowed mode
ShowWindow(getHandle(), SW_NORMAL);
// Show the cursor
ShowCursor(TRUE);
}
return true;
}
我沒有嘗試過,但是您可以通過調用GetConsoleWindow
來獲取控制台窗口的HWND
,然后調用SetClassLong
來設置光標, SetClassLong
更改控制台窗口的鼠標光標。
HCURSOR hNewCursor = LoadCursor(/* whatever*/);
SetClassLong(GetConsoleWindow(), GCL_HCURSOR, hNewCursor);
要使光標消失,請創建一個完全透明的光標。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.