Changing the console size

限于喜欢 提交于 2019-12-06 12:39:15
Wim ten Brink

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.

I now do this:

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;
procedure SetConsoleWindow(NewWidth : integer;NewHeight : integer);

var
  Rect: TSmallRect;
  Coord: TCoord;
  begin { SetConsoleWindow }
  Coord.X := NewWidth;
  Coord.y := NewHeight;
  SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), Coord);
  Rect.Left := 0;   //  must be zero
  Rect.Top := 0;
  Rect.Right := Coord.X - (Rect.Left + 1);
  Rect.Bottom := Coord.y - (Rect.Top + 1);
  SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), True, Rect);
  end; { SetConsoleWindow }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!