C Language Character screen function

Source: Internet
Author: User
Tags function definition set background

The character screen functions of Turbo C2.0 mainly include the setting of text window size, the setting of window color, the Elimination of window text and the input and output functions.

1. Definition of text window

Turbo C2.0 The default defined text window is the entire screen, with a total of 80 columns (or 40 columns) of 25 rows of text units, each containing a character and a property, which is the ASCII character, which defines the color and strength of the character.

The Turbo C2.0 can define a rectangular field on the screen as a window, using the window () function definition.

After the window is defined, the input and output functions for the window can be manipulated only within this window and not beyond the bounds of the window.

The call format for the window () function is:

void window (int left, int. top, int right, int bottom);

The prototype of the function is in conio.h (all functions on the text window are conio.h, followed by no further explanation). The form parameter (int left, int top) in the function is the coordinates of the upper-left corner of the window (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. Turbo C 2.0 stipulates that the upper-left coordinate of the entire screen is (1, 1) and the lower right corner coordinates (80, 25). It also stipulates that the horizontal direction is the x axis, and the direction is toward the right; The y axis is in the vertical direction, and the direction is downward. If the coordinates in the window () function exceed the bounds of the screen coordinates, the definition of the window loses meaning, meaning that the definition will not work, but the program compiles the link without error.

In addition, a screen can define multiple windows, but the current window can only have one (because DOS is a single task operating system), and when you need to use another window, you can call the window () function that defines it again, and this window becomes the current window.

To define a window in the upper-left corner of the screen (20, 5), a window of 30 columns and 15 rows can be written as:

Window (20, 5, 50, 25);

2. text Window color settings

The settings for the text window color include setting the background color and setting the character color, using the function and its invocation format as:

Set background color: void textbackground (int color);

Set character color: void textcolor (int color);

The definition of color is shown in table 1.

表1. 有关颜色的定义
━━━━━━━━━━━━━━━━━━━━━━━━━━━
 符号常数     数值   含义     字符或背景
───────────────────────────
 BLACK       0     黑     两者均可
 BLUE       1     兰     两者均可
 GREEN       2     绿     两者均可
 CYAN       3     青     两者均可
 RED        4     红     两者均可
 MAGENTA      5    洋红     两者均可
 BROWN       6     棕     两者均可
 LIGHTGRAY     7    淡灰     两者均可
 DARKGRAY     8    深灰     只用于字符
 LIGHTBLUE     9    淡兰     只用于字符
 LIGHTGREEN    10    淡绿     只用于字符
 LIGHTCYAN     11    淡青     只用于字符
 LIGHTRED     12    淡红     只用于字符
 LIGHTMAGENTA   13    淡洋红    只用于字符
 YELLOW      14    黄      只用于字符
 WHITE       15    白      只用于字符
 BLINK       128   闪烁     只用于字符
━━━━━━━━━━━━━━━━━━━━━━━━━━━

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.