Dev C++ Console Window Properties

Nikhilesh Sahani picture Nikhilesh Sahani · Jun 22, 2015 · Viewed 8.4k times · Source

I am using Dev C++ v5.6.1 IDE on Windows7.

I have written a C code which has hundreds of line that are displayed as output on screen.

The buffer size of Console Windows is small and I cannot view the initial printf statements. I tried it changing from "properties" option, but it didn't help.

Where Can I find the option to increase the console window buffer size.

Answer

Andreas DM picture Andreas DM · Jun 22, 2015

As you're using Windows, a simple way you can do this is by changing the console window size with the batch command:
mode con: cols=150 lines=50. cols adjusts width, lines adjusts height.

You may choose to call this with system to set the console size.
This is considered bad, more about that here.

// This is considered bad, you shouldn't use system calls.
system("mode con: cols=150 lines=50");

A safer way to do this, is changing the buffer and size using functions defined in <windows.h>.

Here is a small example illustrating this:

#include <stdio.h>
#include <windows.h>

int main(void)
{
    SMALL_RECT rect;
    COORD coord;
    coord.X = 150; // Defining our X and
    coord.Y = 50;  // Y size for buffer.

    rect.Top = 0;
    rect.Left = 0;
    rect.Bottom = coord.Y-1; // height for window
    rect.Right = coord.X-1;  // width for window

    HANDLE hwnd = GetStdHandle(STD_OUTPUT_HANDLE); // get handle
    SetConsoleScreenBufferSize(hwnd, coord);       // set buffer size
    SetConsoleWindowInfo(hwnd, TRUE, &rect);       // set window size

    printf("Resize window");

    return 0;
}

Keep in mind that the function SetConsoleWindowInfo fails if the specified window rectangle extends beyond the boundaries of the console screen buffer. More about that here.