更改控制台大小 [英] Changing the console size

查看:73
本文介绍了更改控制台大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Delphi中的简单问题。我创建了一个控制台应用程序,如果控制台窗口的高度小于80行,则需要将其更改为80行。这需要从代码中完成,并且实际上是在代码中有条件的。 (即,当发生错误时,它会增加控制台的大小,因此可以看到整个(巨大的)错误报告。)

请记住,这是一个控制台应用程序!启动时,它将使用默认控制台,我需要对其进行更改!

Simple problem in Delphi. I've created a console application and I need to change the height of the console window to 80 lines, if it's less than 80 lines. This need to be done from code and is actually conditional within the code. (I.e. when an error occurs, it increases the size of the console so the whole (huge) error report is visible.)
Keep in mind that this is a console application! When it starts, it uses the default console, which I need to alter!

推荐答案

调用SetConsoleWindowInfo()时,Left的值传递给控制台的顶部和顶部必须至少为1,而不是0。问题已解决。

When calling SetConsoleWindowInfo() the values for Left and Top that are passed to the console need to at least be 1, not 0. Problem solved.

我现在这样做:

uses
  Windows;

var
  Rect: TSmallRect;
  Coord: TCoord;
begin
  Rect.Left := 1;
  Rect.Top := 1;
  Rect.Right := 80;
  Rect.Bottom := 60;
  Coord.X := Rect.Right + 1 - Rect.Left;
  Coord.y := Rect.Bottom + 1 - Rect.Top;
  SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), Coord);
  SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), True, Rect);
end;

这篇关于更改控制台大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆