Monday, September 5, 2011

How to resize the console window using C

The code for resizing the console window is given below

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
HANDLE wHnd;    // Handle to write to the console.
HANDLE rHnd;    // Handle to read from the console.
int main(int argc, char* argv[]) {
    // Set up the handles for reading/writing:
    wHnd = GetStdHandle(STD_OUTPUT_HANDLE);
    rHnd = GetStdHandle(STD_INPUT_HANDLE);
    // Change the window title:
    SetConsoleTitle("Advanced C tutorial -");
    // Set up the required window size:
    SMALL_RECT windowSize = {0, 0, 50, 10};
    SetConsoleWindowInfo(wHnd, 1, &windowSize);
    // Change the console window size:
        // Create a COORD to hold the buffer size:
    COORD bufferSize = {10, 10};
    SetConsoleScreenBufferSize(wHnd, bufferSize);
    // Exit
    return 0;


  1. Hey how do i prevent a user from resizing console window in c