1

When I set my win32 console to full screen, the vertical scrollbar disappears. When the text goes to the bottom of the screen, it does not scroll up. Newly written output is not presented to the user because it is below.

This is the style:

if (isFullScreen)
{
    // Set the full screen window style.
    style = GetWindowLong(handle, GWL_STYLE);

    style &= ~(WS_BORDER | WS_CAPTION | WS_THICKFRAME | WS_OVERLAPPEDWINDOW);

    SetWindowLong(handle, GWL_STYLE, style);

    // Minimalize, then show maximized to avoid the cursor blink bug in conhost.exe.
    ShowWindow(handle, SW_MINIMIZE);
    ShowWindow(handle, SW_SHOWMAXIMIZED);

    // Set the font size
    setFontSize(fontSize);
}

I searched the web but it's understandably not common.

How can I add the vertical scrollbar to this while in full screen?

Phil
  • 15
  • 3
  • Is there a reason that you don't use the dedicated API `SetConsoleDisplayMode()` instead of hacking with the window styles? – zett42 May 02 '19 at 14:58
  • Yes. I didn't have any luck with it with Windows 10. If you want to provide a working code example for this purpose, feel free to do so. – Phil May 02 '19 at 18:25

2 Answers2

0

On my computer, I can realize the appearance of full screen console and vertical scrollbar. My system is Win10, using vs2017. This is my code.

#include "pch.h"
#include <iostream>
#include <Windows.h>

void full_screen()
{
    HWND hwnd = GetForegroundWindow();
    int cx = GetSystemMetrics(SM_CXSCREEN);            /* Screen width pixels */
    int cy = GetSystemMetrics(SM_CYSCREEN);            /* Screen Height Pixel */

    LONG l_WinStyle = GetWindowLong(hwnd, GWL_STYLE);   /* Get window information */
    /* Set window information to maximize the removal of title bar and border*/
    SetWindowLong(hwnd, GWL_STYLE, (l_WinStyle | WS_POPUP | WS_MAXIMIZE) & ~WS_CAPTION & ~WS_THICKFRAME & ~WS_BORDER);

    SetWindowPos(hwnd, HWND_TOP, 0, 0, cx, cy, 0);
}

int main()
{
    full_screen();
    while(1)
    {
        std::cout << "Hello World!\n"; 
    }
    return 0;
}

Debug Result:

2

Strive Sun
  • 5,988
  • 1
  • 9
  • 26
  • Thanks for the example! What I found out was I was setting the font size after setting full screen. I learned that is a bad idea. The font size needs to be changed first, and then resize the window. Otherwise, the user's experience looks zoomed in, which is perhaps one reason why the sidebar no longer exists. However, this is a better code solution than my previous. – Phil May 02 '19 at 18:27
  • In addition, I found that the screen buffer size was the same as the window, which would hide the scrollbar. – Phil May 02 '19 at 19:23
  • `GetForegroundWindow()` should be replaced with `GetConsoleWindow()` and the return value should be checked for `nullptr` in case the process is not attached to a console window. – zett42 May 02 '19 at 20:06
0

The official way to set a console to fullscreen is to call SetConsoleDisplayMode().

Under Windows 10 Pro Version 1803 the following code shows a vertical scrollbar without further ado:

#include <iostream>
#include <windows.h>

int main()
{
    HANDLE const hConsole = ::GetStdHandle( STD_OUTPUT_HANDLE );
    if( hConsole == INVALID_HANDLE_VALUE ||
        ! ::SetConsoleDisplayMode( hConsole, CONSOLE_FULLSCREEN_MODE, nullptr ) )
    {
        DWORD const err = ::GetLastError();
        std::cerr << "Failed to set console fullscreen mode. System error: " << err << "\n";
        return 1;
    }

    for( int i = 0; i < 200; ++i )
    {
        std::cout << "Hello World!\n";
    }
    return 0;
}

Note that SetConsoleDisplayMode() can fail if the process is not attached to a console (e. g. by passing the flag CREATE_NO_WINDOW to CreateProcess()) or if STDOUT is redirected to a file.

zett42
  • 25,437
  • 3
  • 35
  • 72
  • With this code alone in a Win32 console project, I continue to get error code 120 "This function is not supported on this system." (OS: Windows 10 Home/Version 1809/64-bit). – Phil May 02 '19 at 20:49
  • @Phil From a quick search, there seem to be [issues with `SetConsoleDisplayMode()` on some OS versions, e. g. Windows 7](https://stackoverflow.com/questions/4423085/c-sharp-full-screen-console). Strange that it doesn't even reliably work across Windows 10 editions. – zett42 May 02 '19 at 21:57
  • It might be good to attempt this, and if it doesn't work, use a more flexible version with Strive Sun - MSFT's code, in order to make sure all systems have the same user experience... well, as far as consoles go. – Phil May 02 '19 at 22:32