How to change Background Color and Display Counter on Screen (At Specific Position) 18-03-2020

Rabia Shahid · Post How to change Background Color and Display Counter on Screen (At Specific Position) 18-03-2020 Posting as GCW CS
The header file graphics.h contains getbkcolor() function which returns the current background color.
Syntax :
int getbkcolor();
As getbkcolor() returns an integer value corresponding to the background color, so below is the table for Color values.
Colors Table :

First of all read all requirements and enlist all functions and header files which is necessary to perform all functions.

#include<conio.h>
 // Used for getch
#include<stdlib.h>
//  Use for  exit (0)
#include<stdio.h>
 // Use for sprintf
#include<graphics.h>
 // Use for loading graphic driver
#include<dos.h>


 // Use for delay
void main()
{
int gd=DETECT,gm;
char ch[5];    
 // we use character array because we want to display counter
//at specific position on screen. That's why we convert int to character
initgraph(&gd,&gm,"..//bgi");
for(int i=10,j=5;i>=0,j<=14;i--,j++)
//for changing background color and counter
{
sprintf(ch,"%d",i);   
//covert counter numbers to character
//if we don't covert int to character then outtextxy give error
setcolor(i);       
//text color
setbkcolor(j);       
//background color
settextstyle(i,HORIZ_DIR,6);  
//text style, direction and size
outtextxy(250,200,ch);  
//display counter at specific position on screen
delay(1000); 
//delay to display movement
cleardevice();
}
exit(0);
getch();
closegraph();
}






Post settings Labels Published on 3/19/20, 1:59 AM Pacific Daylight Time Permalink Location Options

Comments

  1. AOA
    mam main yaha program main to getbkcolor() use to kia nae to get kesay ho raha color
    smj nae ai iss ki

    ReplyDelete
  2. Wasaalm
    getbkcolor() is optional.
    setbkcolor() is use for setting colors.

    ReplyDelete

Post a Comment