Create a resizable window

Asked

Viewed 195 times

10

Hello, I was able to create a console window that does not show scrollbars:

CONSOLE_SCREEN_BUFFER_INFO csbi;
int columns, rows;
COORD size;
COORD BufSize;

while(TRUE) {
    size = GetLargestConsoleWindowSize(GetStdHandle(STD_OUTPUT_HANDLE));
    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
    columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
    rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;

    BufSize.X = columns;
    BufSize.Y = rows;
    SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), BufSize);
    sleep(5);
}

However, the console created by this code does not allow us to increase the size of the console, it can only reduce the size. For this I changed the following lines of code:

columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;

To:

columns = csbi.srWindow.Right - csbi.srWindow.Left + 2;
rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 2;

This way, with some effort, you can increase the size of the console. However, in this way also reappear scroll bars, something I would like not to appear. Does anyone know any solution of how I would adapt the above code so that the scrollbars do not appear, keeping the console window fully resizable?

  • 1

    The scroll bar is displayed when the buffer size is larger than the window size.

  • 2

    @Cypherpotato Yes, I am aware of that fact, which is why I arrived at the results posed in the above question.

1 answer

1

Try adding the following function to your project:

void remove_scrollbar(){

    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO info;
    GetConsoleScreenBufferInfo(handle, &info);
    COORD new_size = 
    {
        csbi.srWindow.Right - csbi.srWindow.Left + 1,
        csbi.srWindow.Bottom - csbi.srWindow.Top + 1
    };
    SetConsoleScreenBufferSize(handle, new_size);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.