In C++, the setbkcolor() is used to define Background Color of the screen. You can set any background color according to your need by using this function.
Syntax of setbkcolor() Function
The general syntax of this function is as follows:
Where:
setbkcolor(co);
co | It represents color. It can be a "int" type value or variable. Its value is from 0 to 15 for VGA screen. It may also be a numerical constant identifier such as BLUE, RED and GREEN etc. |
Example of setbkcolor() Function
The following C++ program displays the word "Welcome" in different colors and also with different background colors.
#include
#include
#include
using namespace std;
main()
{
int driver, mode, co;
driver = DETECT;
initgraph (&driver, &mode, " ");
cleardevice();
for (co = 0; c {
setbkcolor(co);
setbkcolor (co + 1);
settextstyle (0, 0, 2);
outtextxy (100, 10+co*20, "Welcome");
outtextxy(450, 400, "Press any key");
getch();
}
closegraph();
}