How can I resize the Windows console window in C?
如何在C中调整Windows控制台窗口的大小?
1 个解决方案
#1
3
Alright, after much deliberation, I got the code working.
好吧,经过深思熟虑,我得到了代码。
Using this include:
使用这个包括:
#include <windows.h>
This struct:
这个结构体:
struct SMALL_RECT {
SHORT Left;
SHORT Top;
SHORT Right;
SHORT Bottom;
};
And this function:
和这个函数:
void adjustWindowSize()
{
struct SMALL_RECT test;
HANDLE hStdout;
COORD coord;
BOOL ok;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
coord.X = 100;
coord.Y = 50;
ok = SetConsoleScreenBufferSize(hStdout, coord);
test.Left = 0;
test.Top = 0;
test.Right = coord.X-1;
test.Bottom = coord.Y-1;
SetConsoleWindowInfo(hStdout, ok, &test);
} //end adjustWindowSize
I successfully adjusted the size of the console window to the values in coord.X and coord.Y
我成功地将控制台窗口的大小调整为coord.X和coord.Y的值。
#1
3
Alright, after much deliberation, I got the code working.
好吧,经过深思熟虑,我得到了代码。
Using this include:
使用这个包括:
#include <windows.h>
This struct:
这个结构体:
struct SMALL_RECT {
SHORT Left;
SHORT Top;
SHORT Right;
SHORT Bottom;
};
And this function:
和这个函数:
void adjustWindowSize()
{
struct SMALL_RECT test;
HANDLE hStdout;
COORD coord;
BOOL ok;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
coord.X = 100;
coord.Y = 50;
ok = SetConsoleScreenBufferSize(hStdout, coord);
test.Left = 0;
test.Top = 0;
test.Right = coord.X-1;
test.Bottom = coord.Y-1;
SetConsoleWindowInfo(hStdout, ok, &test);
} //end adjustWindowSize
I successfully adjusted the size of the console window to the values in coord.X and coord.Y
我成功地将控制台窗口的大小调整为coord.X和coord.Y的值。