【问题标题】:How do I hide the mouse cursor in a Win32 console?如何在 Win32 控制台中隐藏鼠标光标?
【发布时间】:2018-03-18 16:45:40
【问题描述】:

我有一个将 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;
}

【问题讨论】:

  • 控制台窗口托管在另一个进程中。隐藏进程的鼠标光标不会隐藏控制台进程。
  • 好像是这样。我想以编程方式将鼠标的光标位置移出屏幕是另一种选择。
  • 最大化不等于全屏,Windows Vista+不支持硬件全屏控制台。

标签: c++ winapi


【解决方案1】:

这个我没试过,不过你可以通过调用GetConsoleWindow得到控制台窗口的HWND,然后调用SetClassLong设置光标来改变控制台窗口的鼠标光标。

HCURSOR hNewCursor = LoadCursor(/* whatever*/);
SetClassLong(GetConsoleWindow(), GCL_HCURSOR, hNewCursor);

要使光标消失,请创建一个完全透明的光标。

【讨论】:

  • 我试过了,但我仍然得到默认光标。
  • 控制台窗口托管在另一个进程中。您不能为属于另一个进程的窗口类调用 SetClassLong,也不能从 your 进程传递光标句柄。
猜你喜欢
  • 2015-07-19
  • 1970-01-01
  • 2013-11-30
  • 2022-12-31
  • 2013-09-16
  • 2019-02-06
  • 1970-01-01
  • 2015-05-27
  • 1970-01-01
相关资源
最近更新 更多