Microsoft KB Archive/74614

{|
 * width="100%"|

How _clearscreen, ANSI.SYS Affect Text and Cursor Color

 * }

Q74614

-

The information in this article applies to:


 * The C Run-Time (CRT), included with:
 * Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax
 * Microsoft C/C++ for MS-DOS, version 7.0
 * Microsoft Visual C++, versions 1.0, 1.5

-

SUMMARY
The text and cursor color in a Microsoft C program are affected in various ways by the _settextcolor function in conjunction with the _clearscreen function and whether or not the ANSI.SYS driver is loaded.

MORE INFORMATION
The following are several ways text and cursor color are affected in a C application:


 * The function _settextcolor sets the text color for the functions _outtext and _outmem only.
 * The function _clearscreen will set the text and cursor color to white by default, but will use a different color if one has been previously set [for example, with _settextcolor].
 * The ANSI.SYS driver defines functions that change display graphics, control cursor movement, and reassign keys. Text output is controlled by ANSI.SYS if it is installed.

The following table summarizes how various colors are affected by combinations of ANSI.SYS, _clearscreen, and _settextcolor. An &quot;X&quot; indicates that the displayed color was the color set by _settextcolor. The results were generated by running the sample code below with and without ANSI.SYS installed.

-- -- In the first case, the color of _outtext is affected by _settextcolor. The only way that the output of printf, what the user types, and the cursor color can be affected is by use of ANSI escape sequences.
 * Combinations of ANSI.SYS | _outtext | printf | User  | Cursor |
 * and C Functions*         |  Output    | Output   | Input |        |
 * 1. ANSI/CLRSCR/SETTXTCLR  |      X     |          |       |        |
 * 2.     CLRSCR/SETTXTCLR   |      X     |          |       |        |
 * 3. ANSI/SETTXTCLR/CLRSCR  |      X     |          |       |   X    |
 * 4.     SETTXTCLR/CLRSCR   |      X     |    X     |   X   |   X    |
 * *ANSI=ANSI.SYS  CLRSCR=_clearscreen   SETTXTCLR=_settextcolor |
 * *ANSI=ANSI.SYS  CLRSCR=_clearscreen   SETTXTCLR=_settextcolor |
 * *ANSI=ANSI.SYS  CLRSCR=_clearscreen   SETTXTCLR=_settextcolor |

In the second case, the color of _outtext is affected by _settextcolor.

In the third case, the color of _outtext is affected by _settextcolor. When the subsequent _clearscreen is performed, the text color and the cursor color are affected. However, because ANSI.SYS is installed, the output of printf and what the user types appear in the default white. The only way to change those colors is through the ANSI escape sequences.

In the fourth case, the color of _outtext is affected by _settextcolor. When the subsequent _clearscreen is performed, the text color and the cursor color are affected.

Sample Code
/* Compile options needed: none


 * 1) include 
 * 2) include 
 * 3) include 

void main( void ) {  char line[81];        /* declare a buffer for user input */

/* Clear the screen first, then set the text color. Pause so that you can observe the color of the text output with _outtext and printf, the user input, and the cursor. _clearscreen( _GCLEARSCREEN ); _settextcolor( 5 ); _outtext( &quot;Enter your name: &quot; ); gets( line ); _outtext( &quot;\n\nUsing outtext: Hello &quot; ); _outtext( line ); printf( &quot;\nUsing printf: Press any key to continue...\n&quot; ); while( !kbhit ); getch;

/* Set the text color first, then clear the screen. */

_settextcolor( 3 ); _clearscreen( _GCLEARSCREEN ); _outtext( &quot;Enter your name: &quot; ); gets( line ); _outtext( &quot;\n\nUsing outtext: Goodbye &quot; ); _outtext( line ); printf( &quot;\nUsing printf: The end.\n&quot; ); } Additional query words: kbinf 5.10 6.00 6.00a 6.00ax 7.00 1.00 1.50

Keywords : kb16bitonly

Issue type :

Technology : kbVCsearch kbAudDeveloper kbCRT