-1

I based my function on one which was provided as an answer on a different query here (C++ How to remove vertical scrollbar?), and when I initially used it, it worked fine, however now it has stopped working.

I've copied the other person's solution into mine, and that doesn't work either.

This is my copied code in the main function to try and trim it down as much as possible and it's still not working:

int main() {
 
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
    CONSOLE_SCREEN_BUFFER_INFO screenBuffer;
    GetConsoleScreenBufferInfo(hStdOut, &screenBuffer);

    screenBuffer.dwSize.X = screenBuffer.dwMaximumWindowSize.X;
    screenBuffer.dwSize.Y = screenBuffer.dwMaximumWindowSize.Y;
    SetConsoleScreenBufferSize(hStdOut, screenBuffer.dwSize);

    HWND window = GetConsoleWindow();
    ShowScrollBar(window, SB_BOTH, FALSE);

    getchar();
    return 0;
}
askman
  • 447
  • 4
  • 14
  • 1
    Capture the return value of `ShowScrollBar`. If the return value is false, run [this](https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror) to see what the error code is. – NathanOliver Mar 10 '21 at 17:06
  • damn, it's true – askman Mar 10 '21 at 17:09

2 Answers2

0

When the SetConsoleScreenBufferSize function is executed, the console sometimes does not resize immediately (it takes a while to resize the console), so that ShowScrollBar has hidden the console, and the console has not been resized.

When the console is resized, the scroll bar will reappear. No matter how you hide the scroll bar, the scroll bar will reappear when you resize the console or roll the mouse wheel.

So you can simply add a delay and wait for the console to be resized before ShowScrollBar.

e.p

 ...
 SetConsoleScreenBufferSize(hStdOut, screenBuffer.dwSize);
 Sleep(10);
 HWND window = GetConsoleWindow();
 ShowScrollBar(window, SB_BOTH, FALSE);
Drake Wu
  • 6,927
  • 1
  • 7
  • 30
Strive Sun
  • 5,988
  • 1
  • 9
  • 26
-1

Edit - I think the ShowScrollBar function is bugged as it works intermittently with and without the below.

Updating the window before calling ShowScrollBar seems to have resolved the issue.

int main() {
 
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
    CONSOLE_SCREEN_BUFFER_INFO screenBuffer;
    GetConsoleScreenBufferInfo(hStdOut, &screenBuffer);

    screenBuffer.dwSize.X = screenBuffer.dwMaximumWindowSize.X;
    screenBuffer.dwSize.Y = screenBuffer.dwMaximumWindowSize.Y;
    SetConsoleScreenBufferSize(hStdOut, screenBuffer.dwSize);

    HWND window = GetConsoleWindow();
    UpdateWindow(window);
    ShowScrollBar(window, SB_BOTH, FALSE);

    getchar();
    return 0;
}
askman
  • 447
  • 4
  • 14