好了,经过深思熟虑,我得到了代码工作。
使用这个包括:
#include <windows.h>
这个结构体:
struct SMALL_RECT { SHORT Left; SHORT Top; SHORT Right; SHORT Bottom; };
而这个功能:
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
我成功地将控制台窗口的大小调整为coord.X和coord.Y中的值