Borland C++ reference

setbkcolor

raw OCR

Sets the current background color using the palette.

Defined in header <graphics.h>

Syntax

#include <graphics.h>
void far setbkcolor(int color);

Portability

DOSUNIXWindowsANSI CC++ only
■

Remarks

setbkcolor sets the background to the color specified by color. The argument color can be a name or a number, as listed in the following table:

NumberNameNumberName

These symbolic

0BLACK8DARKGRAY

names are defined

1BLUE9LIGHTBLUE

in graphics. 1^.

2GREEN10LIGHTGREEN
3CYAN11LIGHTCYAN
4RED12LIGHTRED
5MAGENTA13LIGHTMAGENTA
6BROWN14YELLOW
7LIGHTGRAY15WHITE

For example, if you want to set the background color to blue, you can call

setbkcolor(BLUE) /* or */ setbkcolor(1) On CGA and EGA systems, setbkcolor changes the background color by changing the first entry in the palette.

If you use an EGA or a VGA, and you change the palette colors with setpalette or setallpalette, the defined symbolic constants might not give you the correct color. This is because the parameter to setbkcolor indicates the entry number in the current palette rather than a specific color (unless the parameter passed is 0, which always sets the background color to black).

Return value

None.

See also

Example

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)

   /* select driver and mode that supports multiple  background colors */
   int gdriver = EGA, gmode = EGAHI, errorcode;
   int bkcol, maxcolor, x, y;
   char msg[80];
   /* initialize graphics and local variables  */
   initgraph(&gdriver, &gmode, "");
   /* read result of initialization */
   errorcode = graphresult ();
   if (errorcode != grOk) {   /* an error occurred  */
      printf("Graphics error: %s\n", grapherrormsg (errorcode));
      printf("Press any key to halt:");
    . getchO;
      exit(l);               /* terminate with an error  code */
/* maximum color index supported  */
maxcolor = getmaxcolor ();
/* for centering text messages  */
settextjustify (CENTER_TEXT, CENTER_TEXT);
X = getmaxx () / 2;
y = getmaxy () / 2 ;
/* loop through the available colors  */
for  (bkcol=0; bkcol<=maxcolor; bkcol++) {

   /* clear the screen  */
   cleardeviceO  ;

   /* select a nev/ background color */
   setbkcolor (bkcol);

   /* output a messsage  */
   if  (bkcol == WHITE)
      setcolor(EGA_BLUE);
   sprintf(msg, "Background color:  *d", bkcol)
   outtextxy(x, y, msg);
   getchO ;
}
/* clean up */
closegraphO ;
return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.