0

I have been playing around with editing Windows OS console windows. While I was able to successfully disable resizing the console window, I am having trouble disabling the vertical scroll bar that appears to the right of the console. I have tried the following code:

#define _WIN32_WINNT 0x0500

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

int main() {
    
    HWND consoleWindow = GetConsoleWindow(); 

    SetWindowLongPtr(consoleWindow, GWL_STYLE, 
                     GetWindowLong(consoleWindow, GWL_STYLE) 
                     & ~WS_MAXIMIZEBOX & ~WS_SIZEBOX & ~WS_VSCROLL);

    char misc;
    std::cout << "Hello World!";
    std::cin >> misc;
        return 0;

}

I was under the impression the "& ~WS_VSCROLL" segment would disable the vertical scrollbar by modifying that part of the window style, just as the "& ~WS_MAXIMIZEBOX & ~WS_SIZEBOX" disabled resizing. How, then, may I disable the scrollbar?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Sam
  • 1
  • 1
  • Removing the `WS_VSCROLL` style flag would normally work to remove the vertical scrollbar from a window, yes. But the console window is "special". It's not a normal window. It doesn't have normal scrollbars. You need to use the console API to manipulate it. Removing the vertical scrollbar is as easy as making sure there's nothing for it to scroll. You can do this with `SetConsoleScreenBufferSize`. See the duplicate. – Cody Gray - on strike May 26 '23 at 11:52
  • 1
    The "console window" isn't special in any particular way. It is rather utmost generic in that you cannot make **any** assumptions about it. Certainly not the assumption that its `WS_VSCROLL` window style were to be used for anything. Introducing `GetConsoleWindow()` may have been a mistake. – IInspectable May 26 '23 at 12:29
  • 1
    I define a window that does not behave like a bog-standard Windows window as being a "special" window, @IInspectable. Maybe that's just a difference in terminology because I think we're otherwise saying the same thing. – Cody Gray - on strike May 27 '23 at 07:01

0 Answers0