Reputation: 327
I have a Win32 console that is in full screen (windowed). Whenever it is in full screen, I noticed that the console cursor stopped blinking. It just stays as a blank line. I can type with it just fine. It just does not blink for some reason.
It starts off like this...
Console con("My Console");
con.setFullScreen(true);
con.setFontSize(24);
con.write("Enter your name: ");
std::string name = con.readLine();
I narrowed down that the problem is in setFullScreen(true).
This is the code used in that function (specific to full screen):
bool Console::setFullScreen(const bool fullScreen, const bool showScrollBarState,
const bool hideMouseCursor)
{
HWND handle = getHandle();
LONG style;
if (fullScreen)
{
// Set the window style
style = GetWindowLong(handle, GWL_STYLE);
style &= ~(WS_BORDER | WS_CAPTION | WS_THICKFRAME);
SetWindowLong(handle, GWL_STYLE, style);
// Set the window to full screen (windowed mode)
if (!ShowWindow(handle, SW_MAXIMIZE))
return false;
} else { //…}
return true;
}
I narrowed down to this line:
// Set the window to full screen (windowed mode)
if (!ShowWindow(handle, SW_MAXIMIZE))
return false;
If I eliminate this line, a borderless window shows a blinking cursor. If I include this line, the cursor stops blinking. If I set it to SW_NORMAL, it shows a borderless console with a blinking cursor.
For reference, getHandle() has the following code:
HWND Console::getHandle()
{
return GetConsoleWindow();
}
Please let me know. Thanks.
Upvotes: 0
Views: 499
Reputation: 327
As Eryksun pointed out, this appears to be a bug in the WinAPI.
A solution I found for now appears to be call ShowWindow() with SW_MINIMIZE and then call it again with SW_SHOWMAXIMIZED.
For example,
// Set the window to full screen (windowed mode)
ShowWindow(handle, SW_MINIMIZE);
ShowWindow(handle, SW_SHOWMAXIMIZED);
After that, the cursor blinks again.
Upvotes: 2