My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program to print menu base in graphics

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>

void setfocus(int l,int r,int t,int b,char s[])
{
setcolor(RED);
rectangle(l,t,r,b);
setfillstyle(1,YELLOW);
floodfill(l+2,t+2,RED);
setcolor(GREEN);
outtextxy(l+5,t+10,s);
}

void lostfocus(int l,int r,int t,int b,char s[])
{
setcolor(RED);
rectangle(l,t,r,b);
setfillstyle(1,GREEN);
floodfill(l+2,t+2,RED);
setcolor(YELLOW);
outtextxy(l+5,t+10,s);
}

void menu(char x[][50],int msize,int hl)
{
//cleardevice();

int lf,tp,rh,bt;

lf=100;
rh=lf+150;
tp=40;
bt=tp+40;

lostfocus(lf,rh,tp,bt,x[0]);

tp+=40;
bt+=40;

for(int i=1;i<msize;i++)
{

if(i==hl)
setfocus(lf,rh,tp,bt,x[i]);
else
lostfocus(lf,rh,tp,bt,x[i]);

tp+=40;
bt+=40;

}
}

void getkey(int &j,int &k,int &l)
{
REGS n,m;
m.h.ah=0X00;
int86(22,&m,&n);
j=n.h.ah;
k=n.h.al;
m.h.ah=0X02;
int86(22,&m,&n);
l=n.h.al;
}

void main()
{
int d,m,e;
d=DETECT;
initgraph(&d,&m,"c:/tc");
e=graphresult();

if(e!=0)
{
cout<<"Graphics not inialised";
getch();
return;
}
setbkcolor(12);
int ac,sc,st,z=1;

char mstr[][50]={"MENU","IDENTITY","EDUCATION","ADDRESS","CONTACT"};

while(1)
{
menu(mstr,5,z);
getkey(sc,ac,st);
if(sc==72 && z>1)
z--;
else if(sc==80&& z<=4)
{
z++;
if(z==5)
z=0;
}
else if(sc==28)
break;
}

getch();
closegraph();
}

0 comments: