Andrei
Andrei

Reputation: 8894

Win XP console application: API to change width, change height

Win32 console application (printf, fgets, etc)
opens famous 25x80 "black box".

I want my application to programmatically set
different width and height, other than 25x80.

Which APIs can I use to resize my console windows ?

Thanks

Upvotes: 1

Views: 693

Answers (2)

Andrei
Andrei

Reputation: 8894

For the record, I achievd what I needed using weird line

system("mode 42,90");

So weird, but simple, and it worked.

Upvotes: -1

Erik
Erik

Reputation: 91260

Sets the console size to 210*50 and the buffer to 210*2000

COORD s = { 210, 2000 };
SMALL_RECT sr = { 0, 0, 209, 49 };
CONSOLE_SCREEN_BUFFER_INFO sbi = { 0 };
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &sbi);
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), s);
if ( (sbi.srWindow.Right - sbi.srWindow.Left) != (sr.Right - sr.Left) ) {
    SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &sr);
}

Upvotes: 3

Related Questions