resizing console window

Hello
Is it possible to resize the console application window specifically for one program, or even for a part of the program. I have a that reads some values from a data file and they are to long to display in the default window and they wrap into two lines which doesn't look good. So I would like the console window to resize for this function and then go back to normal size, or have the extended size all the time, this doesn't really matter.
Thanks in advance
This isn't possible in a cross-platform way because it is OS-specific. C++ is designed to be used on ANY system, much like C. A computer may not even have a screen, such as the case of telephone communications! In addition, a console may not be in a window. On some Linux distributions, for example, your console is a pure black screen with no GUI interface (your entire screen is a console). It may seem archaic, but it is sometimes necessary and very useful at times. ^_^

With that said, your OS may have such functionality through an API. For example, Windows has the MoveWindow() function that can be used when you include <windows.h>. Check this out:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>

//the following line is necessary for the
//  GetConsoleWindow() function to work!
//it basically says that you are running this
//  program on Windows 2000 or higher
#define _WIN32_WINNT 0x0500

//it is important that the above line be typed
//  BEFORE <windows.h> is included
#include <windows.h>

using namespace std;

int main (void)
{
  HWND console = GetConsoleWindow();
  RECT r;
  GetWindowRect(console, &r); //stores the console's current dimensions

  //MoveWindow(window_handle, x, y, width, height, redraw_window);
  MoveWindow(console, r.left, r.top, 800, 600, TRUE);
  for (int j = 0; j < 100; ++j)
    {
      for (int i = 0x41; i < 0x5B; ++i)
        cout << (char)i;
    }
  cout << endl;
  Sleep(1000);
  MoveWindow(console, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE);
}


AFAIK, the console can't go beyond 800 pixels, so when you specify the width, it has to be 800 or less.

If you need Windows-specific or Linux-specific help, post to those forums rather than here please.

I hope this helps! ^_^

rpgfan
Last edited on
Topic archived. No new replies allowed.