setbkcolor

The function is used to set current drawing background color.

void setbkcolor(COLORREF color);

Parameters

color

Specify the background color to set.

Return Value

None

Remarks

After you set the background color, you don't change the existing background color, but you only change the value of the background color, and then you execute the drawing statement, such as outtextxy, which uses the newly set background color value. If you need to modify all the background colors, you can perform the cleardevice() function after you set the background color.

Examples

The following example enables drawing a red rectangle on a blue background:

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

int main()
{
	// Initialize the graphics window.
	initgraph(640, 480);

	// Set blue as background color.
	setbkcolor(BLUE);
	// Empty screen by background.
	cleardevice();

	// Set red as drawing color.
	setcolor(RED);
	// Draw a rectangle.
	rectangle(100, 100, 300, 300);

	// Press any key to exit.
	_getch();
	closegraph();
}