菜单程序
2008-03-08 12:29:36 来源:WEB开发网核心提示:#include <graphics.h>#include <stdio.h>#include <stdlib.h>#include <bios.h>#include "head.h"#define FALSE 0#define TRUE 1#defi
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
#include <bios.h>
#include "head.h" #define FALSE 0
#define TRUE 1
#define START 1
#define LEFTSHIFT 2
#define RIGHTSHIFT 3
#define ENTER 4
#define EXIT 5
#define UP 6
#define DOWN 7 typedef strUCt{ /*菜单的数据结构*/
int menuID;
char MenuName[10];
int itemCount;
char itemName[4][14];
}menu; void *saveImage; /*保存菜单覆盖的区域*/ int mHeight,mWidth; /*窗口高,宽*/
int mutex=0; menu MainMenu[]=},
},
},
},
},
},
},
},
} };
void showItems(int NewID) /*显示*/
{
int LL,TT,j;
LL=mWidth*NewID+50;
TT=40;
saveImage=malloc(imagesize(LL,31,LL+mWidth+30,70+25*(MainMenu[NewID].itemCount)));
getimage(LL,31,LL+mWidth+30,70+25*(MainMenu[NewID].itemCount),saveImage);
setcolor(7);
setfillstyle(1,7);
rectangle(LL,31,LL+mWidth+30,31+30*(MainMenu[NewID].itemCount));
floodfill(LL+3,33,7);
setcolor(1);
rectangle(LL+5,36,LL+mWidth+25,26+30*(MainMenu[NewID].itemCount));
hz(LL+15,TT,16,1,4,MainMenu[NewID].itemName[0]);
hz(LL,8,16,1,1,MainMenu[NewID].MenuName);
for(j=1;j<(MainMenu[NewID].itemCount);j++)
{
TT=TT+25;
hz(LL+15,TT,16,1,1,MainMenu[NewID].itemName[j]);
}
}
void init()
{
int gdriver,gmode;
gdriver=DETECT;
initgraph(&gdriver,&gmode,"g:\TURBOC2");
if ((fp=fopen("hzk16","rb"))==NULL)
{ PRintf("Can't open haz16,Please add it");
getch(); closegraph(); exit(0);
}
}
initm()
{
int L,T,R,B,i;
mWidth=60;
mHeight=20;
L=50; T=8; R=mWidth+L; B=mHeight+T;
setcolor(7);
setfillstyle(1,7);
rectangle(0,0,640,30);
floodfill(3,25,7);
setcolor(1);
setfillstyle(1,1);
rectangle(0,31,640,449);
floodfill(3,300,1);
setcolor(7);
setfillstyle(1,7);
rectangle(0,450,640,480);
floodfill(3,459,7);
setcolor(15);
line(0,35,640,35);
line(0,38,640,38);
line(0,445,640,445);
line(0,442,640,442);
hz(170,165,80,3,14,"数据结构");
hz(180,240,25,1,12,"(版权所有,随便拷贝)");
hz(L,T,16,1,4,MainMenu[0].MenuName); /*red*/
L=R; R=mWidth+L;
for(i=1;i<9;i++)
{
hz(L,T,16,1,1,MainMenu[i].MenuName); /*blue*/
L=R; R=R+mWidth;
}
} void process(int OldID,int NewID) /*主菜单移动*/
{
int L,T;
L=50+mWidth*OldID;
T=8;
hz(L,T,16,1,1,MainMenu[OldID].MenuName);
L=50+mWidth*NewID;
hz(L,T,16,1,4,MainMenu[NewID].MenuName);
} void process3(int OldID,int NewID,int m) /*子菜单移动*/
{
int LL,TT;
LL=50+mWidth*m;
TT=40+OldID*25;
hz(LL+15,TT,16,1,1,MainMenu[m].itemName[OldID]);
TT=40+NewID*25;
hz(LL+15,TT,16,1,4,MainMenu[m].itemName[NewID]);
}
process1(int d) /* 退出 */
{
if(d==2) exit(1);
} main()
{
int OldID,NewID,head,tail,selectID,quit,c;
int OldID1,NewID1,head1,tail1;
head=0; tail=8;
OldID=0; NewID=0;
OldID1=0; NewID1=0;
head1=0;
quit=0;
init();
initm();
while(!quit)
{
while(bioskey(1)==0);
c=bioskey(0);
if(c==17400) selectID=START;
else if(c==19200) selectID=LEFTSHIFT;
else if(c==19712) selectID=RIGHTSHIFT;
else if(c==7181) selectID=ENTER;
else if(c==283) selectID=EXIT;
else if(c==20480) selectID=DOWN;
else if(c==18432) selectID=UP;
else selectID=NULL;
switch (selectID)
{
case START:
OldID=NewID;
NewID=0;
process(OldID,NewID);
break;
case LEFTSHIFT:
if(mutex==0)
{
if(NewID==head)
{
OldID=NewID;
NewID=tail;
}
else
{
OldID=NewID;
NewID--;
}
process(OldID,NewID);
}
break;
case RIGHTSHIFT:
if(mutex==0)
{
if(NewID==tail)
{
OldID=NewID;
NewID=head;
}
else
{
OldID=NewID;
NewID++;
}
process(OldID,NewID);
}
break;
case ENTER:
if(mutex==0)
{
showItems(NewID);
mutex=1;
tail1=MainMenu[NewID].itemCount-1;
}
else
process1(NewID);
break;
case EXIT:
if(mutex!=0)
{
putimage(mWidth*NewID+50,31,saveImage,COPY_PUT);
hz(mWidth*NewID+50,8,16,1,4,MainMenu[NewID].MenuName);
mutex=0;
}
else
quit=TRUE;
break;
case DOWN:
if(mutex==1)
{
if(NewID1==tail1)
{
OldID1=NewID1;
NewID1=head1;
}
else
{
OldID1=NewID1;
NewID1++;
}
process3(OldID1,NewID1,NewID);
}
break;
case UP:
if(mutex!=0)
{
if(NewID1==head1)
{
OldID1=NewID1;
NewID1=tail1;
}
else
{
OldID1=NewID1;
NewID1--;
}
process3(OldID1,NewID1,NewID);
}
break;
default: break;
}
}
getch();
closegraph(); }
#include <stdio.h>
#include <stdlib.h>
#include <bios.h>
#include "head.h" #define FALSE 0
#define TRUE 1
#define START 1
#define LEFTSHIFT 2
#define RIGHTSHIFT 3
#define ENTER 4
#define EXIT 5
#define UP 6
#define DOWN 7 typedef strUCt{ /*菜单的数据结构*/
int menuID;
char MenuName[10];
int itemCount;
char itemName[4][14];
}menu; void *saveImage; /*保存菜单覆盖的区域*/ int mHeight,mWidth; /*窗口高,宽*/
int mutex=0; menu MainMenu[]=},
},
},
},
},
},
},
},
} };
void showItems(int NewID) /*显示*/
{
int LL,TT,j;
LL=mWidth*NewID+50;
TT=40;
saveImage=malloc(imagesize(LL,31,LL+mWidth+30,70+25*(MainMenu[NewID].itemCount)));
getimage(LL,31,LL+mWidth+30,70+25*(MainMenu[NewID].itemCount),saveImage);
setcolor(7);
setfillstyle(1,7);
rectangle(LL,31,LL+mWidth+30,31+30*(MainMenu[NewID].itemCount));
floodfill(LL+3,33,7);
setcolor(1);
rectangle(LL+5,36,LL+mWidth+25,26+30*(MainMenu[NewID].itemCount));
hz(LL+15,TT,16,1,4,MainMenu[NewID].itemName[0]);
hz(LL,8,16,1,1,MainMenu[NewID].MenuName);
for(j=1;j<(MainMenu[NewID].itemCount);j++)
{
TT=TT+25;
hz(LL+15,TT,16,1,1,MainMenu[NewID].itemName[j]);
}
}
void init()
{
int gdriver,gmode;
gdriver=DETECT;
initgraph(&gdriver,&gmode,"g:\TURBOC2");
if ((fp=fopen("hzk16","rb"))==NULL)
{ PRintf("Can't open haz16,Please add it");
getch(); closegraph(); exit(0);
}
}
initm()
{
int L,T,R,B,i;
mWidth=60;
mHeight=20;
L=50; T=8; R=mWidth+L; B=mHeight+T;
setcolor(7);
setfillstyle(1,7);
rectangle(0,0,640,30);
floodfill(3,25,7);
setcolor(1);
setfillstyle(1,1);
rectangle(0,31,640,449);
floodfill(3,300,1);
setcolor(7);
setfillstyle(1,7);
rectangle(0,450,640,480);
floodfill(3,459,7);
setcolor(15);
line(0,35,640,35);
line(0,38,640,38);
line(0,445,640,445);
line(0,442,640,442);
hz(170,165,80,3,14,"数据结构");
hz(180,240,25,1,12,"(版权所有,随便拷贝)");
hz(L,T,16,1,4,MainMenu[0].MenuName); /*red*/
L=R; R=mWidth+L;
for(i=1;i<9;i++)
{
hz(L,T,16,1,1,MainMenu[i].MenuName); /*blue*/
L=R; R=R+mWidth;
}
} void process(int OldID,int NewID) /*主菜单移动*/
{
int L,T;
L=50+mWidth*OldID;
T=8;
hz(L,T,16,1,1,MainMenu[OldID].MenuName);
L=50+mWidth*NewID;
hz(L,T,16,1,4,MainMenu[NewID].MenuName);
} void process3(int OldID,int NewID,int m) /*子菜单移动*/
{
int LL,TT;
LL=50+mWidth*m;
TT=40+OldID*25;
hz(LL+15,TT,16,1,1,MainMenu[m].itemName[OldID]);
TT=40+NewID*25;
hz(LL+15,TT,16,1,4,MainMenu[m].itemName[NewID]);
}
process1(int d) /* 退出 */
{
if(d==2) exit(1);
} main()
{
int OldID,NewID,head,tail,selectID,quit,c;
int OldID1,NewID1,head1,tail1;
head=0; tail=8;
OldID=0; NewID=0;
OldID1=0; NewID1=0;
head1=0;
quit=0;
init();
initm();
while(!quit)
{
while(bioskey(1)==0);
c=bioskey(0);
if(c==17400) selectID=START;
else if(c==19200) selectID=LEFTSHIFT;
else if(c==19712) selectID=RIGHTSHIFT;
else if(c==7181) selectID=ENTER;
else if(c==283) selectID=EXIT;
else if(c==20480) selectID=DOWN;
else if(c==18432) selectID=UP;
else selectID=NULL;
switch (selectID)
{
case START:
OldID=NewID;
NewID=0;
process(OldID,NewID);
break;
case LEFTSHIFT:
if(mutex==0)
{
if(NewID==head)
{
OldID=NewID;
NewID=tail;
}
else
{
OldID=NewID;
NewID--;
}
process(OldID,NewID);
}
break;
case RIGHTSHIFT:
if(mutex==0)
{
if(NewID==tail)
{
OldID=NewID;
NewID=head;
}
else
{
OldID=NewID;
NewID++;
}
process(OldID,NewID);
}
break;
case ENTER:
if(mutex==0)
{
showItems(NewID);
mutex=1;
tail1=MainMenu[NewID].itemCount-1;
}
else
process1(NewID);
break;
case EXIT:
if(mutex!=0)
{
putimage(mWidth*NewID+50,31,saveImage,COPY_PUT);
hz(mWidth*NewID+50,8,16,1,4,MainMenu[NewID].MenuName);
mutex=0;
}
else
quit=TRUE;
break;
case DOWN:
if(mutex==1)
{
if(NewID1==tail1)
{
OldID1=NewID1;
NewID1=head1;
}
else
{
OldID1=NewID1;
NewID1++;
}
process3(OldID1,NewID1,NewID);
}
break;
case UP:
if(mutex!=0)
{
if(NewID1==head1)
{
OldID1=NewID1;
NewID1=tail1;
}
else
{
OldID1=NewID1;
NewID1--;
}
process3(OldID1,NewID1,NewID);
}
break;
default: break;
}
}
getch();
closegraph(); }
更多精彩
赞助商链接