调整 CMD 窗口大小

发布于 2024-12-06 15:14:19 字数 63 浏览 0 评论 0原文

如何在 C 或 C++ 中以编程方式调整命令提示符窗口的大小?例如 80x25 或 80x40 字符。先感谢您。

How can I resize the Command Prompt window programmatically in C or C++? For example 80x25 or 80x40 characters. Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

木森分化 2024-12-13 15:14:19

MODE 命令允许您设置命令提示符窗口的大小。语法是:

MODE [COLUMNS],[LINES]

例如,对于 80x25 窗口,您将使用

system("MODE 80,25");

This size is associated with a specific instance of the window so other command windows will be set to the default size. It works in both newer WinNT based OSs (i.e. Win2000/XP/7) and Win9x. If the size is not supported it will not change.

将其放在任何输出之前,因为它会清除屏幕。

The MODE command allows you to set the size of the Command Prompt window. The syntax is:

MODE [COLUMNS],[LINES]

For example for a 80x25 window you would use

system("MODE 80,25");

This size is associated with a specific instance of the window so other command windows will be set to the default size. It works in both newer WinNT based OSs (i.e. Win2000/XP/7) and Win9x. If the size is not supported it will not change.

Place it before any output, as it clears the screen.

无远思近则忧 2024-12-13 15:14:19

我做了一些更多的研究,这就是我得出的结论:

#include <windows.h>

int main(){
  system("mode 80,25");   //Set mode to ensure window does not exceed buffer size
  SMALL_RECT WinRect = {0, 0, 80, 25};   //New dimensions for window in 8x12 pixel chars
  SMALL_RECT* WinSize = &WinRect;
  SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), true, WinSize);   //Set new size for window

  //Insert your code here

  return 0;
}

I did some more research and this is what I came up with:

#include <windows.h>

int main(){
  system("mode 80,25");   //Set mode to ensure window does not exceed buffer size
  SMALL_RECT WinRect = {0, 0, 80, 25};   //New dimensions for window in 8x12 pixel chars
  SMALL_RECT* WinSize = &WinRect;
  SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), true, WinSize);   //Set new size for window

  //Insert your code here

  return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文