setbkcolor

This 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, the existing background color is not changed, but only the value of the background color is changed, and then the drawing statement, such as outtextxy, is executed, using 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();
}