Console screen buffer

xiaoxiao2021-03-06  42

The screen buffer is a two-dimensional character and a color array outputted in the console window. One console can contain multiple screen buffers, and the current screen buffer refers to the buffer displayed on the screen.

A screen buffer is created when the system creates a new console. Call the CREATEFILE function Specifies that the CONOUT value can open the current screen buffer of the console. The program can create an additional screen buffer for its console in the CreateConsolescreenBuffer function. A new screen buffer calls the SetConsoleActiveScreenBuffer function with its own handle to be set to the current buffer. However, no matter whether it is a current buffer, it can be accessed to perform read and write operations.

Each screen buffer has its own two-dimensional character information record array. Each character information is stored in a CHAR_INFO structure, which specifies the Unicode or ANSI character and the foreground and background color of the display character.

The associated properties of each screen buffer can be set separately. This also means that the effect of changing the current screen buffer of the console will be interesting. The related properties of the screen buffer include:

The screen buffer size is listed by character. Text properties (Writefile or WriteConsole function is used to "display" the foreground and background used by text). Window size and positioning (rectangular area of ​​the screen buffer displayed in the console window). Cursor position, appearance and visibility. Output mode (enable_processed_output and enable_wrap_at_eol_output). For more information on console output mode, see Advanced Console Mode.

When the screen buffer is created, there is no content. The cursor is visible and is in the origin of the buffer (0, 0), and the upper left corner of the window is coincident with the origin of the buffer. The console screen buffer size, window size, text attributes, and cursor appearance are determined by the system default or user settings. To determine the current different attribute values, you can get getConsolescreenBufferInfo, getConsolecursorInfo and getConsoleMode functions.

To change the application of any console screen buffer property or create your own screen buffer, or save inherited screen buffer status at the beginning and restore it when exiting.

Cursor appearance and positioning

The cursor of the screen buffer can be visible or hidden. It can be seen that its appearance can be fill the entire text cell to the horizontal line of the unit. To get information about the appearance and visibility of the cursor, you can call the getConsolecursorInfo function. Through this function, it is aware that the cursor is visible and the percentage of the unit of the cursor is. And SetConsolecursorinfo can be used to set this information for cursors.

The characters written through the Advanced Console I / O function are output to the current cursor position, and then the cursor is moved. To determine the location of the current cursor (press the coordinate system of the screen buffer), getConsolescreenBufferInfo can be called. Of course, you can set the current location of the cursor through SetConsolecursorPosition and control the location of advanced I / O writes or echo text. If you move the cursor, the new location of the new location will be rewritten (overwritten).

The setting of the cursor position, appearance and visibility of each screen buffer is independent.

Character property

The character properties can be divided into two categories: color and dbcs, the following properties are defined in WinCon.H:

Attribute Meaning FOREGROUND_BLUE FOREGROUND_GREEN text color comprises blue green color of the text comprising the text color comprises red FOREGROUND_INTENSITY FOREGROUND_RED text color highlighting BACKGROUND_BLUE containing a blue background containing a green background BACKGROUND_GREEN BACKGROUND_RED containing a red background background BACKGROUND_INTENSITY highlighted COMMON_LVB_LEADING_BYTE COMMON_LVB_TRAILING_BYTE the last byte of the first byte header COMMON_LVB_GRID_HORIZONTAL Row CommON_lvb_grid_lvertage Left Column CommON_lvb_grid_rvertage Right Column CommON_lvb_reverse_video Turning Prospect and Background Properties Common_LVB_UNDERSCORE Underline Prospect Properties Specify text colors, background properties Specify cell background color, other properties are used with DBCS.

Applications can achieve different color schemes by setting background and foreground color. For example, a blue background is achieved as follows, bright blue text.

Foreground_blue | Foreground_green | Foreground_intensity | Background_Blue

If the background is not specified, the background is black, if the foreground is not specified, the text is black. For example, the following combination declares white background with black text.

Background_blue | Background_green | Background_red

Each screen buffer character unit stores the background and the color properties of the sedent. The application can set color properties separately for each cell and stored in Attributes members of each unit's CHAR_INFO structure. The text attribute of the current screen buffer is used to output or rebound for advanced functions.

The application determines the current text properties of the screen buffer via getConsolescreenBufferInfo, and calls the setConSoleTextAttribute function to set the character properties. Change the screen buffer attribute does not affect the original displayed characters. These text properties do not affect the output of the low-level console I / O (such as WriteConsoleoutPuT, or WriteConsoleoutpubcharacter function), which requires explicitly specify the properties of the cell to be output, or retain the original property.

Font attribute

GetCurrentConsolefont gains the font of the current console and stored in the console_font_info structure, including the height and width information of each character in the font.

GetConsolefontSize gets the font size of the specified console buffer.

转载请注明原文地址:https://www.9cbs.com/read-55246.html

New Post(0)