SetConsoleMode

  BOOL SetConsoleMode(hConsole, fdwMode)    
  HANDLE hConsole; /* console input or output handle */
  DWORD fdwMode; /* input or output mode to set */

The SetConsoleMode function sets the input or output mode for the specified handle.

Parameters

hConsole

Specifies an open handle with GENERIC_WRITE access to a console input buffer or a console screen buffer.

fdwMode

Specifies the input or output mode to set. 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.

Return Value

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.

Comments

A console consists of an input buffer and one or more screen buffers. The mode of a console buffer determines how the console behaves during input or output operations. One set of flag constants affect only input handles, and another set affects only screen buffer (output) handles.

The ENABLE_LINE_INPUT and ENABLE_ECHO_INPUT input modes only affect processes using ReadFile or ReadConsole to read from the console's input buffer. Similarly, ENABLE_PROCESSED_INPUT primarily affects ReadFile and ReadConsole users, except that it also determines whether CTRL-C characters are read by ReadConsoleInput or are passed to the control handler functions.

The ENABLE_WINDOW_INPUT and ENABLE_MOUSE_INPUT input modes determine whether user interactions involving window resizing and mouse actions are reported in the input buffer. These events can be read by ReadConsoleInput, but are always filtered by ReadFile and ReadConsole.

The ENABLE_PROCESSED_OUTPUT and ENABLE_WRAP_AT_EOL_OUTPUT output modes only affect processes using ReadFile (or ReadConsole) and WriteFile (or WriteConsole).

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 output handles are created with ENABLE_PROCESSED_OUTPUT and ENABLE_WRAP_AT_EOL_OUTPUT enabled.

GetConsoleMode is used to determine the current mode of a console handle.

See Also

GetConsoleMode