如何在Win32控制台中隐藏鼠标光标?

时间:2018-03-18 16:45:41

标签: c++ winapi

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

1 个答案:

答案 0 :(得分:-1)

我还没有尝试过这个,但您可以通过调用GetConsoleWindow来获取控制台窗口的HWND,然后调用SetClassLong来更改控制台窗口的鼠标光标。设置光标。

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

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