how can i set my c++ console window size.

can i make my c++ application to open in a specific sized console window.
I want to open my project in n a bigger screen so that all my output is visible. is there any way to do this.. please help.
closed account (Dy7SLyTq)
no you cant, because you cant control the size of a window your process doesnt own. you can however make a gui app
OK thanks
closed account (3qX21hU5)
DTSCode wrote:
no you cant, because you cant control the size of a window your process doesnt own. you can however make a gui app


Actually this is possible... Though it won't be cross platform usually.

On windows it can be accomplished by using the MoveWindow() function. Though you are limited by 800 pixels in size.

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
#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

#include <windows.h>

using namespace std;

int main()
{
    // Get the console handle
    HWND console = GetConsoleWindow();

    //MoveWindow(window_handle, x, y, width, height, redraw_window);
    MoveWindow(console, 100, 100, 100, 100, TRUE);
    Sleep(1000);
    MoveWindow(console, 200, 200, 200, 200, TRUE);
    Sleep(1000);
    MoveWindow(console, 300, 300, 300, 300, TRUE);
    Sleep(1000);
    MoveWindow(console, 400, 400, 400, 400, TRUE);
    Sleep(1000);
    MoveWindow(console, 500, 500, 500, 500, TRUE);

    return 0;
}
Last edited on
Assuming you're talking about a Windows system, is it possible to set the default properties of the console window, while it's open? If you click on the little icon at the top left of the title bar, you get a menu, and two of the options are "Properties" and "Defaults".

The "Properties" option allows you to change the settings for the current window, but the "Defaults" option allows you to change the default settings for all windows of that type that are displayed in the future. They both show the same dialog. If you go to the "Layout" tab, you can change the Window Size to be whatever you like.

Also, you can change the y-value of the Screen Buffer size, to hold a larger number of lines. This is the scroll buffer, so if your program outputs a lot of stuff to the console window, you'll be able to see a lot more of it by scrolling up.

Admittedly, both of these are things you have to do as a user, to manually to configure the properties of the console window. They're not things (as far as I know) that your program can do automatically. So if you run it on another PC. you'll have to repeat those actions again.

closed account (Dy7SLyTq)
i apologize... i thought i was in the *nix section... although i didnt know it could be done on windows either. can it be done in linux?
closed account (3qX21hU5)
I am not to familiar with *nix specific programming but I assume there would be a way. Can do some digging into NCurses to see if that supports it (I would think it would but I am not sure).


Edit: Bah right after I posted did some researching and looks like it is possible with ncurses http://linux.die.net/man/3/resizeterm . Again I am not at all familiar with *nix programming so I am not positive this is what you are looking for but it might be a good starting point.
Last edited on
Topic archived. No new replies allowed.