User Tools

Site Tools


c:graphics.h:setbkcolor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:graphics.h:setbkcolor [2015/05/06 23:06]
c:graphics.h:setbkcolor [2024/02/16 01:05] (current)
Line 1: Line 1:
 +===== setbkcolor =====
 +
 +
 +====Syntax of setbkcolor ==== 
 + <code c>
 +#include <graphics.h>
 +void setbkcolor(int color);
 +  </code>
 +
 +
 +==== Description of setbkcolor ==== 
 +<code c>
 +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).
 +</code>
 +
 +
 +==== Example of setbkcolor ====
 +<code c>
 +/* setbkcolor 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:");
 +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;
 +}
 +</code>
 +
 +
 +==== See also ====
 +[[getbkcolor]]
 +[[setallpalette]]
 +[[setcolor]]
 +[[setpalette]]
 +
 +
 +===== output of setbkcolor example ===== 
 +
 +    no output of example at the moment
 +    do not hesitate and add it...  
 +
 +
  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War

Impressum Datenschutz