各位高人好:那位能帮我看看下面的程序怎么回事,我想将鼠标放在FILE和EDIT上面使起菜单高亮,为什么不行啊!
#include<graphics.h>
#include<dos.h>
struct MENU{
int left,top,right,bottom;
char *head;
};
struct MENU VIEW={100,100,450,300}; /*窗口大小*/
struct MENU FILE={150,150,200,180,"File"}; /*文件子窗口*/
struct MENU EDIT={210,150,260,180,"Edit"}; /*编辑子窗口*/
union REGS i,o;
int button,x,y; /*全局变量*/
void ShowMouse(void); /*显示鼠标函数*/
void StatusMouse(void); /*鼠标状态函数*/
void Process(void); /*处理函数*/
void createbar(struct MENU *t); /*创建窗口函数*/
void createline(struct MENU *t); /*创建窗口亮度函数*/
void outmenufile(struct MENU *t); /*输出文本函数*/
void outmenuedit(struct MENU *t); /*同上*/
int MouseOn(struct MENU *t); /*鼠标操作函数*/
void Hlight(struct MENU *t); /*显示高亮函数*/
void winp(struct MENU *t,int status); /*同上*/
int main(void)
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc");
Process();
getch();
closegraph();
return 0;
}
void Process(void)
{
createbar(&VIEW);
createbar(&FILE);
createbar(&EDIT);
createline(&VIEW);
outmenufile(&FILE);
outmenuedit(&EDIT);
ShowMouse();
StatusMouse();
if(MouseOn(&FILE))
Hlight(&FILE);
if(MouseOn(&EDIT))
Hlight(&EDIT);
}
void createbar(struct MENU *t)
{
setfillstyle(1,7);
bar(t->left,t->top,t->right,t->bottom);
}
void createline(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 outmenufile(struct MENU *t)
{
setcolor(0);
outtextxy(155,155,t->head);
}
void outmenuedit(struct MENU *t)
{
setcolor(0);
outtextxy(215,155,t->head);
}
void ShowMouse(void)
{
i.x.ax=1;
int86(0x33,&i,&o);
}
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;
flag=0;
if(x>=t->left && x<=t->right && y>=t->top && y<=t->bottom)
flag=1;
return flag;
}
void Hlight(struct MENU *t)
{
winp(t,0);
}
void winp(struct MENU *t,int state)
{
if(state==1)
{
setcolor(0);
line(t->left,t->top,t->left,t->bottom);
line(t->left,t->top,t->right,t->top);
setcolor(15);
line(t->right,t->top,t->right,t->bottom);
line(t->left,t->bottom,t->right,t->bottom);
}
else
{
setcolor(15);
line(t->left,t->top,t->left,t->bottom);
line(t->left,t->top,t->right,t->top);
setcolor(0);
line(t->right,t->top,t->right,t->bottom);
line(t->left,t->bottom,t->right,t->bottom);
}
}
那位帮我看看
----------------解决方案--------------------------------------------------------
#include<graphics.h>
#include<dos.h>
struct MENU
{
int left,top,right,bottom ;
char*head ;
}
;
struct MENU VIEW=
{
100,100,450,300
}
;
/*窗口大小*/
struct MENU FILE=
{
150,150,200,180,"File"
}
;
/*文件子窗口*/
struct MENU EDIT=
{
210,150,260,180,"Edit"
}
;
/*编辑子窗口*/
union REGS i,o ;
int button,x,y ;
/*全局变量*/
void ShowMouse(void);
/*显示鼠标函数*/
void StatusMouse(void);
/*鼠标状态函数*/
void Process(void);
/*处理函数*/
void createbar(struct MENU*t);
/*创建窗口函数*/
void createline(struct MENU*t);
/*创建窗口亮度函数*/
void outmenufile(struct MENU*t);
/*输出文本函数*/
void outmenuedit(struct MENU*t);
/*同上*/
int MouseOn(struct MENU*t);
/*鼠标操作函数*/
void Hlight(struct MENU*t);
/*显示高亮函数*/
void winp(struct MENU*t,int status);
/*同上*/
void Process1(void);
int main(void)
{
int gdriver=DETECT,gmode ;
initgraph(&gdriver,&gmode,"c:\\tc");
Process();
while(1)Process1();
getch();
closegraph();
return 0 ;
}
void Process(void)
{
createbar(&VIEW);
createbar(&FILE);
createbar(&EDIT);
createline(&VIEW);
outmenufile(&FILE);
outmenuedit(&EDIT);
}
void Process1(void)
{
ShowMouse();
StatusMouse();
if(MouseOn(&FILE))
Hlight(&FILE);
if(MouseOn(&EDIT))
Hlight(&EDIT);
}
void createbar(struct MENU*t)
{
setfillstyle(1,7);
bar(t->left,t->top,t->right,t->bottom);
}
void createline(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 outmenufile(struct MENU*t)
{
setcolor(0);
outtextxy(155,155,t->head);
}
void outmenuedit(struct MENU*t)
{
setcolor(0);
outtextxy(215,155,t->head);
}
void ShowMouse(void)
{
i.x.ax=1 ;
int86(0x33,&i,&o);
}
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 ;
flag=0 ;
if(x>=t->left&&x<=t->right&&y>=t->top&&y<=t->bottom)
flag=1 ;
return flag ;
}
void Hlight(struct MENU*t)
{
winp(t,0);
}
void winp(struct MENU*t,int state)
{
if(state==1)
{
setcolor(0);
line(t->left,t->top,t->left,t->bottom);
line(t->left,t->top,t->right,t->top);
setcolor(15);
line(t->right,t->top,t->right,t->bottom);
line(t->left,t->bottom,t->right,t->bottom);
}
else
{
setcolor(15);
line(t->left,t->top,t->left,t->bottom);
line(t->left,t->top,t->right,t->top);
setcolor(0);
line(t->right,t->top,t->right,t->bottom);
line(t->left,t->bottom,t->right,t->bottom);
}
}
程式结构有些混乱,问题原因代码已经告诉你了
----------------解决方案--------------------------------------------------------
2楼的绝对是高手
----------------解决方案--------------------------------------------------------