Bài tập C++: Thay đổi màu nền của màn hình



Bài tập

Viết chương trình C++ để thay đổi màu nền của màn hình từ màu đen sang màu trắng.

Lời giải

Bạn theo dõi chương trình C++ sau. Mình sử dụng lệnh setbkcolor để thay đổi màu nền của màn hình.

#include 
#include 
#include 
#include 
using namespace std;
void main()
{
int gdriver=DETECT,gmode,errorcode; //yeu cau auto-detection.
int midx,midy,x;
//khoi tao cac bien do hoa va cuc bo.
initgraph(&gdriver,&gmode,"d:\\bc3\\bgi");
//doc ket qua cua trình khoi tao.
errorcode=graphresult();
if(errorcode!=grOk)
//neu co mot loi xay ra.
{
printf("Xuat hien mot loi : %s \n",grapherrormsg(errorcode));
printf("Nhan bat ky phim nao de dung lai : ");exit(1); //Dung chuong trinh do xuat hien loi.
}
/*thay doi background color.*/
for(x=0;x<=15;x++)
{
setbkcolor(x);}
closegraph();
}

bai_tap_do_hoa_trong_cplusplus.jsp