The character screen function of Turbo C2.0 mainly includes a function of the setting of the text window, the setting of the window color, the clearance of the window text, and the input and output. 1. Definition of the text window TURBO C2.0 default default text window for the entire screen, a total of 80 columns (or 40 columns) 25 rows of text units, including a character and an attribute, a character, an ASCII code character, attribute Specifies the color and intensity of the character. Turbo C2.0 can define a rectangular domain on the screen as a window and define the Window () function. After the window is defined, use the input and output function of the window to operate only within this window without exceeding the boundary of the window. The call format of the Window () function is: Void WINDOW (Int LEFT, INT TOP, INT RIGHT, INT BOTTOM); the prototype of this function is in Conio.h (all the function of all functions of the text window is cono.h, Next, it will not be described later). The form parameter (int LEFT, INT TOP) is the coordinates of the upper left corner of the window, and Int Right, Int bottom is the lower right corner coordinate of the window, where (Left, TOP) and (Right, Bottom) are relative to the entire screen. Words. Turbo C 2.0 specifies that the upper left corner coordinates of the entire screen are (1, 1), and the lower right corner coordinates are (80, 25). It is also specified in the horizontal direction of the X-axis, direction towards the right; in the vertical direction of the Y-axis, the direction is facing down. If the coordinates in the Window () function exceed the boundary of the screen coordinate, the definition of the window will lose its meaning, that is, the definition will not work, but it is not wrong when the program is compiled. Alternatively, a screen can define multiple windows, but the current window can only have one (because DOS is a single task operating system), when you need to use another window, you can call the Window () function that defines the window once again, this This window is a current window. To define a window in the upper left corner of a window (20, 5), the window is 30 columns of 15 rows of windows to be written: Window (20, 5, 50, 25); 2. Settings text window color setting text window color setting Including the setup and character color of the background color, the function and its call format are: Set Background Color: Void TextBackground (INT Color); Set Character Color: Void TextColor (Int Color); See Table 1 for the color definition See Table 1. Table 1. Definition of colors ━━━━━━━━━━━━━━━ 符 符 常━数数 含 字 字━━ 符 符 常数 含 meaning characters or backgrounds ---- ────────────────── Both Black 0 Black Both Ble 1 orchid can be Green 2 green two can CYAN 3, two can be red 4 red two Both Magenta 5 magenta can be BROWN 6-brown two can be LightGray 7 Dark gray Darkgray 8 Dark gray only for character LightBlue 9 Dallan only for character LightGreen 10 light green only for character lightcyan 11 Light blue only used in character lightred 12 Light red only used in Character LightMagenta 13 Dine red only in characters YELLOW 14 yellow only used in Characters White 15 White only used in Characters BLINK 128 Blinking only for characters ━━━━━━ ━━━━━━━━━━━━━━━━━ The symbol constant in the above table is equivalent to the corresponding value, and the two can be interchangeable. For example, set a blue background to use TextBackground (1), you can also use TextBackground (Blue), both without any difference, but the latter is easier to remember, you will know that it is blue. Turbo C also provides a function that can set the character and background color of the text at the same time. This function is called: void texttr (int Attr); where: Attr's value represents the information encoded in color, each representative The meaning is as follows: Bit 7 6 5 4 3 2 1 0 b BBBCCCC ┕┕━┙ ┖───── ┘ ┘ 背景 背景 背景 颜 Character Color byte low four cccc Set Characters Color (0 to 15), 4 ~ 6 Triple BBB sets background color (0 to 7), and the 7th bit b sets the character flashes.
If you want to set up a blue word, the definition method is as follows: Textattr (YELLOW (Blue << 4)); if the character is required to flash, it is defined to: Textattr (128 Yellow (Blue << 4); Note: ( 1) For the background only 0 to 7 total eight colors, if it takes more than 7 less than 15, the representative color is the same as the color corresponding to the lower value. (2) Set with TextbackGround () and TextColor () function settings After the background of the window is not changed before the window is not used, the color does not change until the function clrs CLRSCR (), the entire window and the text characters in the window will become new color. (3) The background color should be left 4 bits when using the TexttTR () function to move the 3-bit background color to the correct location. Below this program uses functions with definitions, color settings, etc., on one screen Different locations define 7 windows, which use seven different colors, respectively. Example 1 .: # include # include # include
Main () {Int i; Textbackground (0); / * Set screen background color * / clrs (); / * Clear text screen * / for (i = 1; i <8; i ) {WINDOW (10 i * 5, 5 i, 30 i * 5, 15 i); / * Define text window * / textbackground (i); / * Define window background color * / clrs (); / * Clear window * /} getCH );
"
INT CPUTS (CHAR * STRING); INT PUTCH; CPRINTF () function outputs a formatted string or value into the window. It is exactly the usage of the Printf () function, distinguishes that the output of the CPRINTF () function is limited by the window, and the output of the Printf () function is the entire screen. The CPUTS () function outputs a string to the screen, which is exactly the same as the PUTS () function method, just limited by the window size. The PUTCH () function outputs a character into the window. Note: (1) Use the above functions, which will automatically go to the beginning of the next line when the right boundary of the window is output. When the content is filled with content in the window, the window screen will automatically roll up one by one to the output. Second, the input function INT getche (void) in the window; the function has been talked before, it is necessary to explain that the getChe () function gets a character from the keyboard, when displayed on the screen, if the character exceeds the window The right boundary is automatically transferred to the beginning of the next line. Below this program gives an exemplary 1. Add some of the output functions of the text. Example 2 .: #include
#include
Int main () {Int i; char * c [] = {"Black", "Blue", "Green", "cyan", "red", "magenta", "brown", "lightgray"}; textbackground 0); / * Set screen background color * / clrs (); / * Clear text screen * / for (i = 1; i <8; i ) {WINDOW (10 i * 5, 5 i, 30 i * 5, 15 i); / * Define text window * / textbackground (i); / * Define window background color * / clrs (); / * Clear window * /} getCh (); return 0;} 4. The function void clrscr (void) of the screen is clearly cleared, and the cursor is positioned at the upper left corner (1, 1) of the window. Void Clreol (Void); Clear all characters from the cursor position to the end of the current window, the cursor position is unchanged. Void gotoxy (x, y); this function is useful, it is used to locate the cursor in the current window. Here X, Y is the coordinate of the cursor to be positioned (relative to the window), when X, Y exceeds the size of the window, the function does not work. INT getText (int XL, int yl, int x2, int y2, void * buffer); int PutText (int X1, int y1, int x2, int y2, void * buffer); GetText () function is specified on the screen The text content in the rectangular area is stored in a memory space pointing to the Buffer pointer. The size of memory is calculated: the byte size used = line number * column number * 2 where: Row number = Y2-Y1 1 column number = X2-x1 1 PutText () function is to save the GetText () function The text content in the memory buffer is copied to the location specified on the screen. INT MOVETEXT (INT X1, INT X2, INT Y2, INT X3, INT Y3); MoveText () function The text of the upper left corner (x1, y1), the lower right corner (x2, y2) is in a rectangular window in the upper left corner (x2, y2) The content is copied to a new location of the upper left corner (X3, Y3). The coordinates of this function are also relative to the entire screen. Note: 1. The coordinates in the getText () function and the PUTText () function are for the entire screen, ie the absolute coordinates of the screen, not the coordinates of the relative window. 2. The MoveText () function is a copy instead of the mobile window area, that is, after the function, the text content of the original location area still exists. Example 3. INCLUDE