Tizer1000
Tizer1000

Reputation: 934

Prevent Console Window Being Resized / Scrolled In C (Window.h)

I'm using window.h in my C program and want to be able to prevent the user from resizing the console window.

Is it possible to remove the scroll bars and "drag to resize" functions (shown in image) of the console window in using C?

Image

Upvotes: 0

Views: 382

Answers (1)

Weather Vane
Weather Vane

Reputation: 34583

You can remove the scroll bars by setting the console text buffer size to the same size as the viewport (tested with Windows 7).

#include <stdio.h>
#include <windows.h>

int main(void)
{
    CONSOLE_SCREEN_BUFFER_INFO info;
    HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    if(GetConsoleScreenBufferInfo(hConsoleOutput, &info)) {
        COORD coord;
        coord.X = info.srWindow.Right - info.srWindow.Left + 1;
        coord.Y = info.srWindow.Bottom - info.srWindow.Top + 1;
        SetConsoleScreenBufferSize(hConsoleOutput, coord);
    }
    getchar();
}

Upvotes: 1

Related Questions