Windows Console: Window-Size und Buffer-Size


#1

Leider kann man mit dem Befehl "mode con: cols=80 lines=25 nur die Buffer-Size der Console ändern.
Mit folgendem C++ Programm kann man beides ändern:

// usage: prog.exe width height [bufferWidth bufferHeight]
#include <windows.h>
#include <stdio.h>

void main(int argc, char *argv[])
{
    short ww, hh, wb, hb;
    if (argc == 3)
    {
        ww = atoi(argv[1]);
        hh = atoi(argv[2]);
        wb = ww;
        hb = hh;
    }
    else if (argc == 5)
    {
        ww = atoi(argv[1]);
        hh = atoi(argv[2]);
        wb = max(atoi(argv[3]), ww);
        hb = max(atoi(argv[4]), hh);
    }
    else 
    {
        printf("Wrong Arguments");
        exit(1);
    }

    COORD      coord = { wb, hb };
    SMALL_RECT rmin  = { 0, 0, 1, 1 };
    SMALL_RECT rect  = { 0, 0, ww-1, hh-1 };

    HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleWindowInfo(Handle, TRUE, &rmin);
    SetConsoleScreenBufferSize(Handle, coord); // bufferSize >= windowSize
    SetConsoleWindowInfo(Handle, TRUE, &rect);

    exit(0);
}