Borland C++ reference

textattr

raw OCR

Sets text attributes.

Defined in header <conio.h>

Syntax

#include <conio.h>
void textattr(int newattr);

Portability

DOSUNIXWindowsANSI CC++ only
■

Remarks

textattr lets you set both the foreground and background colors in a single call. (Normally, you set the attributes with textcolor and textbackground.)

This function does not affect any characters currently on the screen; it only affects those displayed by functions (such as cprintf) performing text mode, direct video output after this function is called.

The color information is encoded in the newattr parameter as follows:

76543210
Bbbbffff

In this 8-bit newattr parameter,

^j^is the 4-bit foreground color (0 to 15). fo&b is the 3-bit background color (0 to 7). B is the blink-enable bit.

If the blink-enable bit is on, the character blinks. This can be accomplished by adding the constant BLINK to the attribute.

If you use the symbolic color constants defined in conio.h for creating text attributes with textattr, note the following limitations on the color you select for the background:

■ You can only select one of the first eight colors for the background. ■ You must shift the selected background color left by 4 bits to move it into the correct bit positions.

These symbolic constants are listed in the following table:

Numeric

Symbolic constantvalueForeground or background?
BLACK0Both
BLUE1Both
GREEN2Both
CYAN3Both
RED4Both
MAGENTA5Both
BROWN6Both
LIGHTGRAY7Both
DARKGRAY8Foreground only
LIGHTBLUE9Foreground only
LIGHTGREEN10Foreground only
LIGHTCYAN11Foreground only
LIGHTRED12Foreground only
LIGHTMAGENTA13Foreground only
YELLOW14Foreground only
WHITE15Foreground only
BLINK128Foreground only

Return value

None.

See also

Example

#include <conio.h>

int main(void)
{
   int i;
   clrscrO ;
   for (i = 0; i < 9; i++)  {
       textattr(i +  ((i+1) « 4));
       cprintf("This is a test\r\n");
   }
   return 0;
}

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.