How _clearscreen(), ANSI.SYS Affect Text and Cursor ColorID: Q74614
|
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.
The following are several ways text and cursor color are affected in a
C application:
----------------------------------------------------------------------
| 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() |
----------------------------------------------------------------------
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.
/* Compile options needed: none
*/
#include <graph.h>
#include <stdio.h>
#include <conio.h>
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( "Enter your name: " );
gets( line );
_outtext( "\n\nUsing outtext: Hello " );
_outtext( line );
printf( "\nUsing printf: Press any key to continue...\n" );
while( !kbhit( ) );
getch( );
/* Set the text color first, then clear the screen. */
_settextcolor( 3 );
_clearscreen( _GCLEARSCREEN );
_outtext( "Enter your name: " );
gets( line );
_outtext( "\n\nUsing outtext: Goodbye " );
_outtext( line );
printf( "\nUsing printf: The end.\n" );
}
Additional query words: kbinf 5.10 6.00 6.00a 6.00ax 7.00 1.00 1.50
Keywords : kb16bitonly
Version :
Platform :
Issue type :
Last Reviewed: August 5, 1999