Windows Console

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by MCWNT (talk | contribs) at 16:04, 29 December 2007. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

File:PowerShell.PNG
Windows PowerShell using the Win32 console window on Windows Vista.

Win32 console is a plain text window within the system of Windows API. A Win32 console has a screen buffer and an input buffer.

Win32 consoles are typically used for applications that do not need to display images (e.g. for command line tools), including command line interpreters, terminal emulators, Perl, PHP (CLI), or text user interfaces such as FAR Manager, for example. However, contrary to what some people believe, a Win32 Console applcation is just a special form of any native Win32 application - it is not a 16-bit DOS application.

Details

The input buffer is a queue where events are stored (from keyboard, mouse etc). The output buffer is a rectangular grid where characters are stored, together with their attributes. A console window may have several output buffers, only one of which is active (i.e. displayed) for a given moment.

The console window may be displayed as a normal window on the desktop, or may be switched to full screen to use the actual hardware text mode. Unfortunately, the display mode is locked in background intensity mode, thus blinking does not work. Also, the underscore attribute is not available.

Programs may access a Win32 console either via high-level functions (such as ReadConsole and WriteConsole) or via low-level functions (e.g. ReadConsoleInput and WriteConsoleOutput).

Win32 console applications are often mistaken for MS-DOS applications, especially on Windows 9x and Windows Me.

In earlier versions of Windows, there was no native support for consoles. Since Windows 3.1 and earlier was merely a graphical interface for MS-DOS, most text applications that ran on earlier Windows versions were actually MS-DOS applications running in "DOS boxes". To simplify the task of porting applications to Windows, early versions of Visual C++ were supplied with QuickWin, a library that implemented basic console functionality inside a regular Window.

Windows 9x and Me support

Windows 95/98/Me support is relatively poor compared to Windows NT, because the console window runs in the system VM and so keyboard input to a Win32 console application had to be directed to it by conagent.exe running in a DOS VM that are also used for real DOS applications by hooking the keyboard interrupt. conagent.exe then calls Vcond (which is a VxD). Vcond then had to pass the keyboard input to the System VM, and then finally to the Win32 console application. Besides performance, another problem with this implementation is that drives that are local to a DOS VM are not visible to a Win32 console application. This can cause confusion.

Unicode support

Under Windows 95/98/Me, the screen buffer mirrors the structure of VGA text buffer, with two bytes per character cell: one byte for character code, one byte for attributes (the character must be in OEM character set, the attribute is with high-intensity background/no blinking). This speeds up operation considerably if the actual VGA text mode is used.

Under Windows NT/2000/XP/CE, the screen buffer uses four bytes per character cell: two bytes for character code, two bytes for attributes. The character is then encoded as Unicode (UTF-16).[1][2] For backward compatibility, the console APIs exist in two versions: Unicode and non-Unicode. The non-Unicode versions of APIs can use code page switching to extend the range of displayed characters (but only if TrueType fonts are used for the console window, thereby extending the range of codes available). Even UTF-8 is available as "code page 65001".

See also

Notes

  1. ^ UTF-16 uses surrogate pairs to extend 16-bit codes to the full Unicode range.
  2. ^ "Working with Surrogate Pairs". Microsoft. 2007. Retrieved 2007-11-19.

External links