How _clearscreen(), ANSI.SYS Affect Text and Cursor Color

ID: Q74614


The information in this article applies to:


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 following table summarizes how various colors are affected by combinations of ANSI.SYS, _clearscreen(), and _settextcolor(). An "X" 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.

----------------------------------------------------------------------
| 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.

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
*/ 

#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