Take the 2-minute tour ×

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!

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

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:

  Rect: TSmallRect;
  Coord: TCoord;
  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);
share|improve this answer
add comment

Your Answer


