Making the console window bigger in C

前端 未结 1 780
小鲜肉
小鲜肉 2021-01-17 04:36

How can I resize the Windows console window in C?

1条回答
  •  迷失自我
    2021-01-17 04:59

    Alright, after much deliberation, I got the code working.

    Using this include:

    #include 
    

    This struct:

    struct SMALL_RECT {
        SHORT Left;
        SHORT Top;
        SHORT Right;
        SHORT Bottom;
    };
    

    And this function:

    void adjustWindowSize()
    {
        struct SMALL_RECT test; 
    
        HANDLE hStdout;
        COORD coord;
        BOOL ok;
    
        hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
        coord.X = 100;
        coord.Y = 50;
        ok = SetConsoleScreenBufferSize(hStdout, coord);
    
        test.Left = 0;
        test.Top = 0;
        test.Right = coord.X-1;
        test.Bottom = coord.Y-1;
    
        SetConsoleWindowInfo(hStdout, ok, &test);
    
    } //end adjustWindowSize 
    

    I successfully adjusted the size of the console window to the values in coord.X and coord.Y

    0 讨论(0)
提交回复
热议问题