17.3.11 Buffer Resize Events

If the input handle is in window aware mode,the console window's menu allows the user to change the size of the active screen buffer, generating a buffer size event. If not in window aware mode, the screen buffer resize menu option is disabled. Changes to the screen buffer size due to application calls to SetConsoleScreenBufferSize are not reported as events in the input buffer. In a buffer size event, the Event field of the input record will be a WINDOW_BUFFER_SIZE_RECORD containing the new size of the active screen buffer. The X coordinate of the new size is the number of characters per row and the Y coordinate is the number of rows. If the user reduces the size of the screen buffer, any data in the discarded portion is lost.

The following code fragment might be used by a thread whose purpose was to continuously read input from the input buffer and dispatch the events to the appropriate handlers:

DWORD NumRead;

BOOL bResult;

INPUT_RECORD InputBuffer[100];

HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE));

int i;

while (1) {

/* wait for events */

bResult = ReadConsoleInput(hStdIn, InputBuffer,

100, &NumRead);

if (!bResult) { /* handle error */ }

/* dispatch the events to the appropriate handler */

for (i=0; i<NumRead; i++) {

switch(InputBuffer[i].EventType) {

case KEY_EVENT:

doKeyEvent(InputBuffer[i].Event.KeyEvent);

break;

case MOUSE_EVENT:

doMouseEvent(InputBuffer[i].Event.MouseEvent);

break;

case WINDOW_BUFFER_SIZE_EVENT:

rows =

InputBuffer[i].Event.WindowBufferSizeEvent.dwSize.Y;

cols =

InputBuffer[i].Event.WindowBufferSizeEvent.dwSize.X;

AdjustScreenDisplay(rows, cols);

break;

default:

/* error: unknown event type */

break;

}

}

}