_settextcolor

Description

Sets the current text color.

#include <graph.h>

short __far _settextcolor( short index );

index Desired color index  

Remarks

The _settextcolor function sets the current text color to the color index specified by index. The default text color is the same as the maximum color index for the current video mode.

The _settextcolor routine sets the color for the _outtext and _outmem functions only. It does not affect the color of the printf function or the color of text output with the _outgtext font routine. Use the _setcolor function to change the color of font output.

In text color mode, you can specify a color index in the range 0–31. The colors in the range 0–15 are interpreted as normal (non-blinking). The normal color range is defined below:

Index Color Index Color

0 Black 8 Dark gray
1 Blue 9 Light blue
2 Green 10 Light green
3 Cyan 11 Light cyan
4 Red 12 Light red
5 Magenta 13 Light magenta
6 Brown 14 Yellow
7 White 15 Bright white

Blinking is selected by adding 16 to the normal color value.

In every text mode, including monochrome, _getvideoconfig returns the value 32 for the number of available colors. The value 32 indicates the range of values (0–31) accepted by the _settextcolor function. This includes sixteen normal colors (0–15) and sixteen blinking colors (16–31). Monochrome text mode has fewer unique display attributes, so some color values are redundant. However, because blinking is selected in the same manner, monochrome text mode has the same range (0–31) as other text modes.

Return Value

The function returns the color index of the previous text color. There is no error return. Use the _grstatus function to check the status after a call to _settextcolor.

Compatibility

Standards:None

16-Bit:DOS

32-Bit:None

See Also

_gettextcolor, _grstatus, _outmem, _outtext

Example

/* OUTTXT.C: This example illustrates text output functions:

* _gettextcolor _getbkcolor _gettextposition _outtext

* _settextcolor _setbkcolor _settextposition

*/

#include <conio.h>

#include <stdio.h>

#include <graph.h>

char buffer [80];

void main( void )

{

/* Save original foreground, background, and text position */

short blink, fgd, oldfgd;

long bgd, oldbgd;

struct _rccoord oldpos;

/* Save original foreground, background, and text position. */

oldfgd = _gettextcolor();

oldbgd = _getbkcolor();

oldpos = _gettextposition();

_clearscreen( _GCLEARSCREEN );

/* First time no blink, second time blinking. */

for( blink = 0; blink <= 16; blink += 16 )

{

/* Loop through 8 background colors. */

for( bgd = 0; bgd < 8; bgd++ )

{

_setbkcolor( bgd );

_settextposition( (short)bgd + ((blink / 16) * 9) + 3, 1 );

_settextcolor( 7 );

sprintf(buffer, "Back: %d Fore:", bgd );

_outtext( buffer );

/* Loop through 16 foreground colors. */

for( fgd = 0; fgd < 16; fgd++ )

{

_settextcolor( fgd + blink );

sprintf( buffer, " %2d ", fgd + blink );

_outtext( buffer );

}

}

}

_getch();

/* Restore original foreground, background, and text position. */

_settextcolor( oldfgd );

_setbkcolor( oldbgd );

_clearscreen( _GCLEARSCREEN );

_settextposition( oldpos.row, oldpos.col );

exit( 0 );

}