【问题标题】:Dev C++ Console Window Properties开发 C++ 控制台窗口属性
【发布时间】:2015-09-07 12:13:54
【问题描述】:

我在 Windows7 上使用 Dev C++ v5.6.1 IDE。

我编写了一个 C 代码,其中有数百行在屏幕上显示为输出。

控制台窗口的缓冲区很小,我无法查看初始的 printf 语句。 我尝试将它从“属性”选项更改,但没有帮助。

在哪里可以找到增加控制台窗口缓冲区大小的选项。

【问题讨论】:

  • 如果缓冲区已满,您可以编写命令 -> 暂停。按任意键连续显示。
  • 试试这个,可能会有帮助 ...int main() { system("mode 128"); ... }

标签: c++ c windows ide dev-c++


【解决方案1】:

当您使用 Windows 时,一种简单的方法是使用批处理命令更改控制台窗口大小:
mode con: cols=150 lines=50。 cols 调整 width,lines 调整 height

您可以选择使用系统调用它来设置控制台大小。
这被认为是 不好,关于here的更多信息。

// This is considered bad, you shouldn't use system calls.
system("mode con: cols=150 lines=50");

一种更安全的方法是使用<windows.h> 中定义的函数更改缓冲区和大小。

下面是一个小例子来说明这一点:

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

int main(void)
{
    SMALL_RECT rect;
    COORD coord;
    coord.X = 150; // Defining our X and
    coord.Y = 50;  // Y size for buffer.

    rect.Top = 0;
    rect.Left = 0;
    rect.Bottom = coord.Y-1; // height for window
    rect.Right = coord.X-1;  // width for window

    HANDLE hwnd = GetStdHandle(STD_OUTPUT_HANDLE); // get handle
    SetConsoleScreenBufferSize(hwnd, coord);       // set buffer size
    SetConsoleWindowInfo(hwnd, TRUE, &rect);       // set window size

    printf("Resize window");

    return 0;
}

请记住,如果指定的窗口矩形超出控制台屏幕缓冲区的边界,则函数 SetConsoleWindowInfo 将失败。更多关于 here.

【讨论】:

    猜你喜欢
    • 2010-12-26
    • 1970-01-01
    • 2013-06-30
    • 1970-01-01
    • 2014-04-20
    • 2019-01-18
    • 2014-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多