斑竹:您好!麻烦你再帮我看看,怎么回事,程序越来越混乱了呢?下面的程序为什么我单击菜单不能弹出其子菜单呢?
#include<graphics.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>
struct menu{
int left,top,right,bottom;
char *head;
};
struct menu File={150,90,200,110,"File"};
struct menu Edit={250,90,300,110,"Edit"};
struct menu Help={350,90,400,110,"Help"};
struct menu Close={620,20,630,30,"x"};
struct menu Title={100,20,540,50};
struct menu Mainmenu={100,70,540,120};
struct menu Text={100,150,540,450};
struct menu Print={50,455,590,475};
union REGS i,o;
int button,x,y;
void show_mouse(void); /*显示鼠标函数*/
void set_fill_screen(void); /*设置整个屏幕函数*/
void process_program(void); /*处理函数*/
void set_title_screen(struct menu *t); /*设置标题窗口*/
void set_mainmenu_screen(struct menu *t); /*设置主要菜单*/
void set_text_screen(struct menu *t); /*设置文本窗口*/
void set_print_screen(struct menu *t); /*设置打印窗口*/
void comment(void); /*注解函数*/
void draw_button(struct menu *t); /*绘制按纽函数*/
int status_mouse(void); /*鼠标状况函数*/
int mouse_on(struct menu *t); /*鼠标放在哪个菜单函数*/
void display_sub_menu(struct menu *t,int n,char *H[]); /*显示下级菜单函数*/
void high_light(struct menu *t); /*高亮显示函数*/
int main(void)
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc"); /*图形初始化*/
show_mouse(); /*显示鼠标*/
set_fill_screen(); /*设置屏幕*/
process_program(); /*处理函数*/
getch();
closegraph();
return 0;
}
void show_mouse(void) /*显示鼠标函数*/
{
i.x.ax=1;
int86(0x33,&i,&o);
}
void set_fill_screen(void) /*设置整个屏幕函数*/
{
setfillstyle(1,3);
bar(0,0,640,480);
clrscr();
}
void process_program(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"}; /*帮助子菜单*/
set_title_screen(&Title); /*设置标题窗口*/
set_mainmenu_screen(&Mainmenu); /*设置主要菜单*/
set_text_screen(&Text); /*设置文本窗口*/
set_print_screen(&Print); /*设置打印窗口*/
comment(); /*注解*/
draw_button(&File); /*绘制按纽*/
draw_button(&Edit);
draw_button(&Help);
draw_button(&Close);
while(1)
{
if(status_mouse()==1) /*检测鼠标状态*/
{
if(mouse_on(&File))
display_sub_menu(&File,5,fm);
if(mouse_on(&Edit))
display_sub_menu(&Edit,6,em);
if(mouse_on(&Help))
display_sub_menu(&Help,2,hm);
if(mouse_on(&Close))
exit(0);
}
else
{
if(mouse_on(&File))
high_light(&File);
if(mouse_on(&Edit))
high_light(&Edit);
if(mouse_on(&Help))
high_light(&Help);
if(mouse_on(&Close))
high_light(&Close);
}
if(kbhit()) /*检测从键盘输入的字符*/
{
KEY=getch();
if(KEY==27) /*输入ESC退出*/
{
outtextxy(250,350,"Bye::Bye");
sleep(1);
exit(0);
}
}
}/*while*/
}
void set_title_screen(struct menu *t) /*设置标题*/
{
setfillstyle(1,0);
bar(t->left,t->top,t->right,t->bottom);
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 set_mainmenu_screen(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->right,t->top,t->right,t->bottom);
line(t->left,t->bottom,t->right,t->bottom);
}
void set_text_screen(struct menu *t) /*设置文本窗口*/
{
setfillstyle(1,2);
bar(t->left,t->top,t->right,t->bottom);
setcolor(0);
line(t->left,t->top,t->right,t->top);
line(t->left,t->top,t->left,t->bottom);
setcolor(15);
line(t->left,t->bottom,t->right,t->bottom);
line(t->right,t->top,t->right,t->bottom);
}
void set_print_screen(struct menu *t) /*设置输出窗口*/
{
setfillstyle(1,0);
bar(t->left,t->top,t->right,t->bottom);
setcolor(0);
line(t->left,t->top,t->right,t->top);
line(t->left,t->top,t->left,t->bottom);
setcolor(15);
line(t->left,t->bottom,t->right,t->bottom);
line(t->right,t->top,t->right,t->bottom);
}
void comment(void) /*解释函数*/
{
char text_string1[]="This is my first graph menu!";
char text_string2[]="Hello Friend!";
char text_string3[]="Here is an with my menu program.";
char text_string4[]="As you can see it's like windows menu ,you can";
char text_string5[]="add more menus to it.It's just a concept for";
char text_string6[]="build more menus.I hope you will like my effort,";
char text_string7[]="email me at : chentianqiao06@163.com.";
char text_string8[]="__chentianqiao.";
char text_string9[]="2006-03-01.";
setcolor(15);
outtextxy(200,30,text_string1);
outtextxy(150,170,text_string2);
outtextxy(150,190,text_string3);
outtextxy(150,210,text_string4);
outtextxy(150,230,text_string5);
outtextxy(150,250,text_string6);
outtextxy(150,270,text_string7);
outtextxy(390,290,text_string8);
outtextxy(390,310,text_string9);
}
void draw_button(struct menu *t) /*绘制菜单按纽*/
{
setcolor(0);
outtextxy(t->left+2,t->top+2,t->head);
}
int status_mouse(void) /*鼠标状态函数*/
{
i.x.ax=3;
int86(0x33,&i,&o);
button=o.x.bx;
x=o.x.cx;
y=o.x.dx;
return button;
}
int mouse_on(struct menu *t) /*鼠标*/
{
int flag=0;
if(x>=t->left && x<=t->right && y>=t->top && y<=t->bottom)
flag=1;
return flag;
}
void display_sub_menu(struct menu *t,int n,char *H[]) /*显示下级菜单*/
{
int j;
unsigned area;
void *mapbuffer;
area=imagesize(100,120,540,450);
mapbuffer=malloc(area);
getimage(100,120,540,450,mapbuffer);
setfillstyle(1,3);
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(j=0;j<n;j++)
{
setcolor(0);
outtextxy(t->left+5,t->top+100+j*20,H[j]);
}
sleep(3);
putimage(100,120,mapbuffer,COPY_PUT);
free(mapbuffer);
}
void high_light(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);
while(1) /*detect mouse state*/
{
status_mouse();
if(mouse_on(t)!=1) /*cancel high_light*/
{
setcolor(3);
rectangle(t->left,t->top,t->right,t->bottom);
break;
}
}
我都快晕了。
[此贴子已经被作者于2006-3-6 19:37:36编辑过]