Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>textattr() set both foreground and background colors</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 textattr()              Set Both Foreground and Background Colors

 #include   <conio.h>

 void       textattr(attrib);
 int        attrib;

    textattr() sets the forground and background colors in a single call.
    Only those characters displayed using direct console output functions
    after textattr() has been called are affected.

    The color information is represented by an 8-bit 'attrib' value: the
    four lowest bits represent the foreground color (0-15).  The next
    three bits represent the background color(0-7).  The high bit is the
    blink-enable bit. If this bit is on, the character will blink. The
    symbolic constant BLINK is defined in <conio.h> and can be added to
    the foreground and/or background color(s) to make the character
    blink.

    The allowable colors, their symbolic constants and corresponding
    values are defined in <conio.h> :

    Symbolic constant    Value     Foreground &/or Background
     BLACK                 0            Both
     BLUE             1            Both
     GREEN                 2            Both
     CYAN             3            Both
     RED                   4            Both
     MAGENTA               5       Both
     BROWN                 6            Both
     LIGHTGRAY        7            Both
     DARKGRAY         8            Foreground
     LIGHTBLUE        9            Foreground
     LIGHTGREEN           10            Foreground
     LIGHTCYAN       11            Foreground
     LIGHTRED        12            Foreground
     LIGHTMAGENTA    13            Foreground
     YELLOW               14            Foreground
     WHITE                15            Foreground
     BLINK               128            Foreground


    Note that because the background color is set using only 3 bits, only
    the first eight colors can be used. The color selected must also be
    shifted left by 4 bits to shift it into the correct bit positions
    (CYAN<<4).


       Returns:     Nothing.

   Portability:     IBM PC and compatibles only.

 ------------------------------ Example ---------------------------------
    The following statements print a blinking message in yellow text on a
    green background.

           #include <conio.h>

           main()
           {

               textattr(YELLOW + (GREEN<<4) + BLINK);
                cputs("YOU'LL SEE BLINKING YELLOW TEXT ON A GREEN
                        BACKGROUND.");
           }


See Also: textbackground() textcolor()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson