Hi!
As a beginner in C/C++ I'm now practicing console applications under C++ Builder. Could anybody please tell me how to enlarge the default size of the programs' console? It is too litle for some of my applications and I wasn't able to find out an enlarging recipe in the C++ Builder environment.
Thanks in advance!

Dani AI

Generated

Brief summary and practical options (complements to and )

's shortcut/properties advice applies to the Windows cmd shortcut, and 's GetConsoleWindow()/ShowWindow() trick does work to maximize the console. For a reliable, reproducible size you can set the console buffer and window size programmatically (so every run starts at the dimensions you want). Important: the screen buffer must be at least as large as the window, otherwise the window-size call will fail.

Example: set buffer then window (call early in main)

#include <windows.h>

void SetConsoleSize(short cols, short rows)
{
    HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
    if (h == INVALID_HANDLE_VALUE) return;

    COORD buf = { cols, rows };
    SetConsoleScreenBufferSize(h, buf);

    SMALL_RECT rect = { 0, 0, (short)(cols - 1), (short)(rows - 1) };
    SetConsoleWindowInfo(h, TRUE, &rect);
}

Quick alternatives and tips

  • One-line quick fix: system("mode con: cols=120 lines=40"); (works early in main).
  • To make a GUI or IDE-launched console keep a size via Windows dialog, set a fixed console title from code (SetConsoleTitle("MyProgConsole")), then open the Properties dialog for that window and "Save properties for window with same title".
  • When debugging inside C++Builder the IDE may recreate or size the console differently; test the final exe outside the IDE to confirm persistence.
  • If calls fail, call GetLastError() — common cause: buffer smaller than requested window, or requested size exceeds current display limits. For GUI apps use AllocConsole() first.

These approaches give programmatic control (preferred) and make results reproducible across runs and machines, complementing the suggestions already posted in the thread.

Recommended Answers

All 5 Replies

If you are a beginner better to do it by hand. Right click the command prompt shortcut in accessories, and select Properties. Then select the layout tab. There you can change the width and height. There are other options that can be set in the other tabs. Then when you click apply,select "save properties for window with same title."

If you are a beginner better to do it by hand. Right click the command prompt shortcut in accessories, and select Properties. Then select the layout tab. There you can change the width and height. There are other options that can be set in the other tabs. Then when you click apply,select "save properties for window with same title."

To Moderator.
1) Please first notice you just described above how to enlarge the Windows command prompt console, which I've already enlarged at the right time (I mean when installing my Windows).
2) However, you might just learn now that the default size of C++ Builder programs' console is a completely different matter than the one of the command prompt Windows accessory. Therefore your advice from above might be useful to you and your lovers at most.
3) Please do notice I was asking about how to do something while your answer was about how not to do that. So you might agree you were unpolite.
Best regards!
---------------------------
To forum participants.
Grateful thanks for any solution to my former problem!

1) Please first notice you just described above how to enlarge the Windows command prompt console, which I've already enlarged at the right time (I mean when installing my Windows).

First time I heard of someone like you, who changes the console size at installation.

2) However, you might just learn now that the default size of C++ Builder programs' console is a completely different matter than the one of the command prompt Windows accessory. Therefore your advice from above might be useful to you and your lovers at most.

Too bad. Don't you have anything better to do with your lovers?

Well if it is different from the command prompt, you can do it like this.
1. Click the icon of the C++ Builder command window
2. Select properties
3. Change the layout

3) Please do notice I was asking about how to do something while your answer was about how not to do that. So you might agree you were unpolite.

No I dont agree. I have done the same thing for my visual studio command prompt and it worked. I dont think you have even tried my solution. Anyway since this is your first false accusation, I will leave you in peace.

maybe this will help

#define _WIN32_WINNT 0x500
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
   HWND hWnd = GetConsoleWindow();
    ShowWindow(hWnd,SW_MAXIMIZE);
    cout << "Hello World\n";
    cin.get();
   return 0;
}

Grateful thanks Ancient Dragon,
Your code does work like a dream! You and other participants may trust there is no unfair bit in my claims from above.
Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.