BOOL GetConsoleMode( hConsole, lpfdwMode) | |||||
HANDLE hConsole; | /* console input or output handle | */ | |||
LPDWORD lpfdwMode; | /* receives current mode flags | */ |
The GetConsoleMode function retrieves the input or output mode for the specified console.
hConsole
Specifies an open handle with GENERIC_READ access to a console input buffer or a console screen buffer.
lpfdwMode
Points to a variable to receive the current mode of the specified buffer. If hConsole is an input handle, the mode may be a combination of the following values:
Value | Meaning |
ENABLE_LINE_INPUT | If set, ReadFile or ReadConsole will return only when a CR (carriage return) character is read. If not set, ReadFile or ReadConsole returns when one or more characters are available. |
ENABLE_ECHO_INPUT | Can only be used if ENABLE_LINE_INPUT is also set. Characters read by ReadFile or ReadConsole will be written to the screen as they are read. |
ENABLE_PROCESSED_INPUT | CTRL-C will be processed by the system and not placed in the input buffer. If the input buffer is being read by ReadFile or ReadConsole, other control keys are processed by the system and not returned in the ReadFile or ReadConsole buffer. If ENABLE_LINE_INPUT is also set, BKSP (backspace), TAB, CR (carriage return), LF (linefeed), and bell will be handled by the system. |
ENABLE_WINDOW_INPUT | User interactions that change the size of the console screen buffer will be reported in the console's input buffer. Information about these events can be read from the input buffer by applications using ReadConsoleInput, but not by those using ReadFile or ReadConsole. |
ENABLE_MOUSE_INPUT | Mouse events generated by mouse movement and button presses are placed in the input buffer, if the mouse pointer is within the borders of the console window and the window has the keyboard focus. These events can not be read using ReadFile or ReadConsole. |
If hConsole is an output handle, the mode may be a combination of the following values:
Value | Meaning |
ENABLE_PROCESSED_OUTPUT | Characters written by WriteFile (or WriteConsole) or echoed by ReadFile (or ReadConsole) are parsed for ASCII control sequences and the correct action is performed. BKSP (backspace), TAB, bell, CR (carriage return) and LF (linefeed) characters are processed. |
ENABLE_WRAP_AT_EOL_OUTPUT | When writing with WriteFile (or WriteConsole) or echoing with ReadFile (or ReadConsole), the cursor will move to the beginning of the next line when it reaches the end of the current row. This can result in scrolling the lines displayed in the window, or in scrolling the contents of the screen buffer and discarding the top line (when the cursor goes beyond the bottom, right cell). If disabled, the last character in the row is overwritten. |
The return value is TRUE if the function was successful, or FALSE if an error occurred. Use the GetLastError function to obtain extended error information.
By default, all input handles are created with ENABLE_LINE_INPUT, ENABLE_ECHO_INPUT, ENABLE_PROCESSED_INPUT, ENABLE_WINDOW_INPUT and ENABLE_MOUSE_INPUT enabled, and all screen buffer handles are created with ENABLE_PROCESSED_OUTPUT and ENABLE_WRAP_AT_EOL_OUTPUT enabled.
The SetConsoleMode function lets you change a console's input and output modes.
This example takes different actions based on whether a console is set up for line or character mode:
HANDLE hConsoleInput;
DWORD fdwModeFlags;
if (GetConsoleMode(hConsoleInput, &fdwModeFlags))
if (fdwModeFlags & ENABLE_LINE_INPUT) {
/* we're in line mode ... so do line mode stuff */
}
else {
/* we're in character mode ... so do character mode stuff */
}
}
else {
/* deal with failure of GetConsoleMode call */
}
SetConsoleMode