RAD Studio
ContentsIndex
PreviousUpNext
textattr

Header File 

conio.h  

Category 

Console I/O Routines 

Prototype 

void textattr(int newattr); 

Description 

Sets text attributes.

Note: Do not use this function in Win32 GUI applications.
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 onscreen; it affects only those characters 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: 

In this 8-bit newattr parameter:

  • bits 0-3 contain the 4-bit foreground color (0 to 15).
  • bits 4-6 contain the 3-bit background color (0 to 7).
  • bit 8 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 select only 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: 

Return Value 

None. 

Example  

#include <conio.h>
int main(void)
{
   int i;
   clrscr();
   for (i=0; i<9; i++)
   {
       textattr(i + ((i+1) << 4));
       cprintf("This is a test\r\n");
   }
   return 0;
}

Portability

POSIX 
Win32 
ANSI C 
ANSI C++ 
 
 
 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!