求助高人!菜单程序问题!
各位大哥哥好:请帮我运行运行看一下,为什么我的程序只能用鼠标点一次,第二次就出错误啊!#include<dos.h>
#include<string.h>
#include<stdlib.h>
#include<graphics.h>
struct MENU{
int left,top,right,bottom;
char *head;
};
struct MENU FirstView={50,50,550,400};
struct MENU SecondView={100,100,500,150};
struct MENU File={110,110,160,130,"File"};
struct MENU Edit={170,110,220,130,"Edit"};
struct MENU Help={230,110,280,130,"Help"};
struct MENU Close={520,60,540,80,"x"};
struct MENU SubView={100,160,500,350};
struct MENU Text={100,360,500,380};
union REGS i,o;
int button,x,y;
void ShowMouse(void);
void Process(void);
void buildView(struct MENU *t);
void buildLine(struct MENU *t);
void StatusMouse(void);
int MouseOn(struct MENU *t);
void Hlight(struct MENU *t);
void comment(void);
void buildSubView(void);
void cancel(struct MENU *t);
void textarea(struct MENU *t);
void print(struct MENU *t);
void clearprint();
void PullMenuDown(char *H[],int n,struct MENU *t);
int main(void)
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc");
ShowMouse();
Process();
getch();
closegraph();
}
void ShowMouse(void)
{
i.x.ax=1;
int86(0x33,&i,&o);
}
void Process(void)
{
char KEY;
char *fm[]={"New","Open","Save","Save as","Exit"};
char *em[]={"Undo","Cut","Copy","Paste","Delete","Select All"};
char *hm[]={"Help Topics","About Menus"};
buildView(&FirstView);
buildLine(&FirstView);
buildView(&SecondView);
buildLine(&SecondView);
buildSubView();
buildLine(&SubView);
comment();
while(1) /*主要就是这里*/
{
if(kbhit())
{
KEY=getch();
if(KEY==27|| KEY==45)
{
outtextxy(250,300,"Bye::Bye");
sleep(1);
exit(0);
}
}
StatusMouse();
if(button==1)
{
if(MouseOn(&File))
PullMenuDown(fm,5,&File);
if(MouseOn(&Edit))
PullMenuDown(em,6,&Edit);
if(MouseOn(&Help))
PullMenuDown(hm,2,&Help);
if(MouseOn(&Close))
exit(0);
}
else
{
if(MouseOn(&File))
{
Hlight(&File);
print(&File);
sleep(1);
clearprint();
cancel(&File);
}
if(MouseOn(&Edit))
{
Hlight(&Edit);
print(&Edit);
sleep(1);
clearprint();
cancel(&Edit);
}
if(MouseOn(&Help))
{
Hlight(&Help);
print(&Help);
sleep(1);
clearprint();
cancel(&Help);
}
if(MouseOn(&Close))
{
Hlight(&Close);
print(&Close);
sleep(1);
cancel(&Close);
}
}
}
}
void buildView(struct MENU *t)
{
setfillstyle(1,7);
bar(t->left,t->top,t->right,t->bottom);
}
void buildLine(struct MENU *t)
{
setcolor(15);
line(t->left,t->top,t->right,t->top);
line(t->left,t->top,t->left,t->bottom);
setcolor(0);
line(t->left,t->bottom,t->right,t->bottom);
line(t->right,t->top,t->right,t->bottom);
}
void StatusMouse(void)
{
i.x.ax=3;
int86(0x33,&i,&o);
button=o.x.bx;
x=o.x.cx;
y=o.x.dx;
}
int MouseOn(struct MENU *t)
{
int flag=0;
if(x>=t->left && x<=t->right && y>=t->top && y<=t->bottom)
flag=1;
return flag;
}
void Hlight(struct MENU *t)
{
setcolor(15);
line(t->left,t->top,t->right,t->top);
line(t->left,t->top,t->left,t->bottom);
setcolor(0);
line(t->left,t->bottom,t->right,t->bottom);
line(t->right,t->top,t->right,t->bottom);
}
void comment(void)
{
char textstring1[]={"This is my first program."};
char textstring2[]={"I hope you like."};
char textstring3[]={"My name is chentianqiao."};
char textstring4[]={"Bye--Bye"};
char textstring5[]={"Please look."};
char textstring6[]={"Put Mouse on the \"x\",Exit."};
char textstring7[]={"press ESC exit."};
setcolor(0);
outtextxy(525,65,Close.head);
outtextxy(250,70,textstring5);
outtextxy(File.left+10,File.top+5,File.head);
outtextxy(Edit.left+10,Edit.top+5,Edit.head);
outtextxy(Help.left+10,Help.top+5,Help.head);
outtextxy(150,170,textstring1);
outtextxy(150,190,textstring2);
outtextxy(150,210,textstring3);
outtextxy(150,230,textstring4);
outtextxy(150,250,textstring6);
outtextxy(150,270,textstring7);
textarea(&Text);
}
void buildSubView(void)
{
setfillstyle(1,2);
bar(100,160,500,350);
}
void cancel(struct MENU *t)
{
setcolor(7);
rectangle(t->left,t->top,t->right,t->bottom);
}
void textarea(struct MENU *t)
{
setcolor(0);
line(t->left,t->top,t->right,t->top);
line(t->left,t->top,t->left,t->bottom);
setcolor(15);
line(t->right,t->top,t->right,t->bottom);
line(t->left,t->bottom,t->right,t->bottom);
}
void print(struct MENU *t)
{
if(strcmp(t->head,"x")==0)
outtextxy(250,365,"Exit");
else
outtextxy(250,365,t->head);
}
void clearprint(void)
{
setfillstyle(1,7);
bar(152,362,498,378);
}
void PullMenuDown(char *H[],int n,struct MENU *t)
{
int i;
unsigned area;
void *mapbuffer;
area=imagesize(100,100,400,400);
mapbuffer=malloc(area);
getimage(100,100,400,400,mapbuffer);
setfillstyle(1,7);
bar(t->left,t->top+40,t->right+100,t->bottom+200);
setcolor(15);
line(t->left,t->top+40,t->right+100,t->top+40);
line(t->left,t->top+40,t->left,t->bottom+200);
setcolor(0);
line(t->left,t->bottom+200,t->right+100,t->bottom+200);
line(t->right+100,t->top+40,t->right+100,t->bottom+200);
for(i=0;i<n;i++)
{
setcolor(0);
outtextxy(t->left+50,t->top+100+20*i,H[i]);
}
sleep(1);
putimage(100,100,mapbuffer,COPY_PUT);
}