#include"dos.h"
#include"graphics.h"
#include"alloc.h"
char *menu[]={"Samosa","Sandwich","Dahiwada",...
union REGS i,o;
main()
{
int gd=DETECT,gm,choice=1,bill=0,width=0,i,c...
char **buffer;
initgraph(%26amp;gd,%26amp;gm,"c:\\c\\bgi");
if(initmouse()==-1)
{
printf("\nUnable to initialise mouse..");
exit();
}
count=sizeof(menu)/sizeof(char*);
settextstyle(TRIPLEX_FONT,0.3);
displaymenu(menu,count,100,100);
for(i=0,i%26lt;count;i++)
{
if(textwidth(menu[i](%26lt;width)
width=textwidth(menu[i])
{buffer=malloc(sizeof(menu));
savemenu(menu,buffer,width,count,100,1...
while(choice!=4)
{
choice=getresponce(menu,buffer,width,c...
gotoxy(50,15);
printf("You selected %s",menu[choice-1]);
}
}
displaymenu(char**menu,int count,int x1 ,int y1)
{int i,h;
h=textheight(menu[0]);
for(i=0;i%26lt;count;i++)
outtextxy(x1,y1+i*(h+5),menu[i]);
}
savemenu(char**menu,char**buffer,int width,int count,int x1,int y1)
{
int i,x2,yy1,yy2,area,h;
h=textheight(menu[0]);
for(i=0;i%26lt;count;i++)
{
x2=x1+width;
yy1=y1+i*(h+5);
yy2=y1+(i+1)*(h+5);
area+imagesize(x1,yy1,x2,yy2);
buffer[i]=malloc(area);
getimage(x1,yy1,x2,yy2,buffer[i]);
}
}
getresponce(char**menu,char**buffer,in... width,int count,int x1,int y1)
{
int choice=1,prevchoice=0,x,y,x2,y2,button;
int in,i,h;
h=textheight(menu[0]);
y2=y1+count*(h+5);
x2=x1+width;
rectangle(x1-5,y1-5,x2+5,y2+5);
while(1)
{ getmousepos(%26amp;button,%26amp;x,%26amp;y);
if(x%26gt;=x1%26lt;=x2%26amp;%26amp;y%26gt;=y1%26amp;%26amp;y%26lt;=y2)
{
in=1;
for(i=1;i%26lt;=count;i++)
{
if(y%26lt;=y1+i*(h+5))
{
choice=i;
break;
}}
if(prevchoice!=choice)
{
hidemouseptr();
highlight(buffer,choice,h,x1,y1);
if(prevchoise)
dehighlight(buffer,prevchoice,h,x1,y1)...
prevchoise=choice;
showmouseptr();
}
if((button%26amp;1)==1)
{
while((button%26amp;1)==1)
getmousepos(%26amp;button,%26amp;x,%26amp;y);
if(x%26gt;=x1%26amp;%26amp;x%26lt;=x2%26amp;%26amp;y%26gt;=y1%26amp;%26amp;y%26lt;=y2)
return(choice);
}
}
else
{
if(in==1)
{
in=0;
prevchoice=0;
hidemouseptr();
dehighlight(buffer,choice,h,x1,y1);
showmouseptr();
}
}
}
}
highlight(char **buffer,int ch, int h, int x1, int y1)
{
putimage(x1,y1+(ch-1)*(h+5),buffer[ch-...
}
dehighlight(char**buffer,int ch, int h, int x1, int y1)
{
putimage(x1,y1+(ch-1)*(h+5),buffer[ch-...
}
initmouse()
{
i.x.ax=0;
int86(0x33,%26amp;i,%26amp;o);
return(o.x.ax==0?-1:0);
}
showmouseptr()
{
i.x.ax=1;
int86(0x33,%26amp;i,%26amp;o);
}
hidemouseptr()
{
i.x.ax=2;
int86(0x33,%26amp;i,%26amp;o);
}
getmousepos(int *button,int *x, int *y)
{
i.x.ax=3;
int86(0x33,%26amp;i,%26amp;o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}
Whats wrong in this Turbo C program?
There are many errors in the program
soem of hem are
Line no. 4, 7, 9 are incomplete and ; are missing
correct for of initgraph is
initgraph(%26amp;gd,%26amp;gm,"..\\bgi");
Reply:Turbo products compile memory addresses differently.
beware.
Reply:change your buffer declaration to *buffer[20];
initialize buffer[0..19] to NULL
remove buffer = malloc(sizeof(menu))
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment