Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Console mode window resizing

Status
Not open for further replies.

waltp9999

Programmer
Jun 17, 2002
32
US
I'm trying to resize a console window and can't find the appropriate calls. SetConsoleScreenBufferSize() will allow the window to grow larger but not smaller. SetConsoleWindowInfo() simply returns error 6 (invalid handle).

All other calls I find deal with pixels but in order to use these calls, I need the current font Size, but can't find that call either.

Any idea where I can look next?

Thanks
Walt
 
I think this algorithm should help (width and height are wanted sizes):
Code:
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  COORD coordScreen;
  HANDLE Screen;
  BOOL bSuccess;
  SMALL_RECT srWindowRect;

  Screen = GetStdHandle(STD_OUTPUT_HANDLE);
  ASSERT((Screen != INVALID_HANDLE_VALUE));

  bSuccess = GetConsoleScreenBufferInfo(Screen, &csbi);
  ASSERT(bSuccess);

  /* get the largest size we can size the console window to */
  coordScreen = GetLargestConsoleWindowSize(Screen);
  ASSERT(coordScreen.X | coordScreen.Y);

  /* set window size to 1,1 in order to set any buffer size */
  srWindowRect.Left = srWindowRect.Top = (SHORT) 0;
  srWindowRect.Right = srWindowRect.Bottom = (SHORT) 1;
  bSuccess = SetConsoleWindowInfo(Screen, TRUE, &srWindowRect);
  ASSERT(bSuccess);

  /* define the new console window size and scroll position */
  srWindowRect.Right = (SHORT) (min(width, coordScreen.X) - 1);
  srWindowRect.Bottom = (SHORT) (min(height, coordScreen.Y) - 1);  

  /* define the new console buffer size */
  coordScreen.X = width;
  coordScreen.Y = height;

  bSuccess = SetConsoleScreenBufferSize(Screen, coordScreen);
  ASSERT(bSuccess);
  bSuccess = SetConsoleWindowInfo(Screen, TRUE, &srWindowRect);
  ASSERT(bSuccess);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top