1

I am trying to make a fun program where it display random numbers, but I need to remove the scrollbar so it looks more convincing. I managed to make the program full screen but I can't remove the vertical scrollbar. Screenshot

Code:

#include <iostream>
#include <Windows.h>
using namespace std;

int main() {
    SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, 0);
    int output;
    bool done = false;
    system("color a");
    while (!done) {
        output = 1 + (rand() % (int)(1000 - 1 + 1));
        cout << output;
    }
}
drescherjm
  • 10,365
  • 5
  • 44
  • 64
  • You could clear the screen when it gets full, so a scroll bar never has a chance to show. – Carcigenicate Mar 03 '17 at 12:43
  • Do you know a way of doing that? –  Mar 03 '17 at 12:45
  • There's multiple ways of clearing a console, but which ways work depend on the console bring used. `system("cls")` will clear the screen, but I'll probably get yelled at for even suggesting you use `system`. Also, you can look up ANSI escape codes. One of the clears the screen. – Carcigenicate Mar 03 '17 at 12:48
  • Take a look here: http://superuser.com/questions/1108489/how-to-remove-scrollbar-in-cmd-windows-10 –  Mar 03 '17 at 12:56
  • And here if you want to do it with code: http://stackoverflow.com/questions/3471520/how-to-remove-scrollbars-in-console-windows-c –  Mar 03 '17 at 12:57
  • When I try to user the code I get this error: SetConsoleScreenBufferSize() failed! Reason : 87 Screen Buffer Size : 120 x 9001 –  Mar 03 '17 at 13:03
  • 1
    Looks like you are not properly using function `GetConsoleScreenBufferInfo()`, post the new failing code in order to solve the issue. BTW if screen Y size is 9001 you have a super Monitor resolution! – Rama Mar 03 '17 at 13:11

1 Answers1

1

There are many ways, one of them is manipulating the size of the internal buffer of the console to have the same size of the window and then using ShowScrollBar function to remove the scrolls.

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

using namespace std;

int main() {
    SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, 0);

    HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(hstdout, &csbi);

    csbi.dwSize.X = csbi.dwMaximumWindowSize.X;
    csbi.dwSize.Y = csbi.dwMaximumWindowSize.Y;
    SetConsoleScreenBufferSize(hstdout, csbi.dwSize);

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

    int output;
    bool done = false;
    system("color a");

    while (!done) {
        output = 1 + (rand() % (int)(1000 - 1 + 1));
        cout << output;

    }
}

Another way is to rely on conio.h or another C/C++ header/library which implements user interface functions.

Hugo Corrá
  • 14,546
  • 3
  • 27
  • 39