| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 534 人关注过本帖
标题:求助高人!菜单程序问题!
只看楼主 加入收藏
梦想中国
Rank: 2
等 级:新手上路
威 望:5
帖 子:539
专家分:0
注 册:2006-2-26
收藏
 问题点数:0 回复次数:4 
求助高人!菜单程序问题!
各位大哥哥好:请帮我运行运行看一下,为什么我的程序只能用鼠标点一次,第二次就出错误啊!
#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);
}
搜索更多相关主题的帖子: 菜单 高人 
2006-02-28 09:41
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
收藏
得分:0 
#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);
int 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)
{
while(!kbhit())
{
/* if(kbhit())
{
KEY=getch();
if(KEY==27||KEY==45)
{
outtextxy(250,300,"Bye::Bye");
sleep(1);
exit(0);
}
}
*/
// StatusMouse();
if(StatusMouse()==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);所有sleep是你的问题根源
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);
}
}
}

KEY=getch();
if(KEY==27||KEY==45)
{
outtextxy(250,300,"Bye::Bye");
sleep(1);
exit(0);
}
}
}
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);
}
int StatusMouse(void)
{
i.x.ax=3 ;
int86(0x33,&i,&o);
button=o.x.bx ;
x=o.x.cx ;
y=o.x.dx ;
return button ;
}
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(3);
putimage(100,100,mapbuffer,COPY_PUT);
free(mapbuffer);//少了这句是个严重问题

}

九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2006-02-28 13:42
梦想中国
Rank: 2
等 级:新手上路
威 望:5
帖 子:539
专家分:0
注 册:2006-2-26
收藏
得分:0 
多谢斑竹指教

2006-02-28 14:30
梦想中国
Rank: 2
等 级:新手上路
威 望:5
帖 子:539
专家分:0
注 册:2006-2-26
收藏
得分:0 
if(StatusMouse()==1)
此句斑竹说的不对,不能改

2006-02-28 15:07
梦想中国
Rank: 2
等 级:新手上路
威 望:5
帖 子:539
专家分:0
注 册:2006-2-26
收藏
得分:0 
尊敬的斑竹:我想不出来怎么能加一个判断了,麻烦您给写上一个好吗?

2006-02-28 15:45
快速回复:求助高人!菜单程序问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028856 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved