===== setbkcolor =====
====Syntax of setbkcolor ====
#include
void setbkcolor(int color);
==== Description of setbkcolor ====
setbkcolor sets the background to the color specified by color. The
argument color can be a name or a number as listed below. (These symbolic
names are defined in graphics.h.)
Name Value
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15
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).
==== Example of setbkcolor ====
/* setbkcolor example */
#include
#include
#include
#include
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:");
getch();
exit(1); /* 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 */
cleardevice();
/* select a new background color */
setbkcolor(bkcol);
/* output a messsage */
if (bkcol == WHITE)
setcolor(EGA_BLUE);
sprintf(msg, "Background color: %d", bkcol);
outtextxy(x, y, msg);
getch();
}
/* clean up */
closegraph();
return 0;
}
==== See also ====
[[getbkcolor]]
[[setallpalette]]
[[setcolor]]
[[setpalette]]
===== output of setbkcolor example =====
no output of example at the moment
do not hesitate and add it...