这是本人自编的在DOS下的比较全面操作的图形中文菜单!不过当前目录需要有UCDOS自带的几个字库文件!hzk24h,hzk24k文件
/*---------------------------------------------------------------------------
File: MENU.C
Function: Operate MainMenu
---------------------------------------------------------------------------*/
# define MAX_FRAME 4
# define UP 72
# define DOWN 80
# define LEFT 75
# define RIGHT 77
# define ESC 27
# define F1 59
# define DEL 83
# define SPACE 32
# define ENTER 13
# define Alt_X 45
# define Alt_Y 21
# define Alt_D 32
# define Alt_T 20
# define Alt_O 24
# define BackSpace 8
struct gmenu{
int left,top;
char *menuname;
char *submenu[7];
int count,width;
}menuframe[MAX_FRAME]={
{15,31,"数据库操作(D)",{"打开库文件",
"显示库结构",
"显示记录内容",
"记录查找",
"关闭库文件",
"-",
"退出ALT+X"},7,14,},
{175,31,"函数曲线图(T)",{"SIN函数",
"COS函数",
"TAN函数",
"CTG函数",
"-",
"B组设计"},6,12,},
{335,31,"软件(DIY)",{"窗口颜色",
"窗口字体颜色",
"主菜单设置",
"子菜单设置",
"-",
"系统填充模式",
"用户定义模式",},7,12,},
{480,31,"其他(O)",{"老鼠闯迷宫",
"串口通讯传输",
"音乐欣赏",
"-",
"系统还原",
"帮助F1",
"关于"},7,12,}};
char *title="C语言程序综合设计";
int diy_style=1,diy_ufill=-1,diy_color=BLUE,diy_bkcolor=LIGHTGRAY,chang=0;
int diy_sgkcolor=RED,diy_sgcolor=WHITE,diy_mgkcolor=CYAN,diy_mgcolor=BLUE;
int setmenu(void)
{ int title_x=200;
setbkcolor(BLUE);
setcolor(WHITE);
Tbox(2,2,getmaxx()-2,getmaxy()-2,LIGHTGRAY,BLUE,4);
dis_hz(title_x,8,title,YELLOW);
Tline(6,getmaxy()-32,getmaxx()-6,getmaxy()-32);
setfillstyle(0,1);bar(10,getmaxy()-28,getmaxx()-10,getmaxy()-7);
dis_hz(10,getmaxy()-28,"操作导航:请选择………",WHITE);
dis_hz(getmaxx()-12-7*16,getmaxy()-28,"退出ALT+X",WHITE);
listtopmenu();return 0;
}
int listtopmenu(void)
{ int i;
Tbutton(7,28,getmaxx()-8,53,diy_bkcolor,diy_color,NULL,0,diy_style);
for (i=0;i<MAX_FRAME;i++)
Tbutton(menuframe[i].left,menuframe[i].top,menuframe[i].left+(strlen(menuframe[i].menuname)+2)*8,menuframe[i].top+20,diy_bkcolor,diy_color,menuframe[i].menuname,0,diy_style);
return 0;
}
int loadmenu(int which)
{int i,keylr,size,sleft,stop,zwidth,swidth,scount,atop,ptop,subwhich;
void *buffer;
subwhich=keylr=sleft=stop=0;
while (1)
{setfillstyle(0,1);bar(90,getmaxy()-28,getmaxx()-8*16,getmaxy()-7);
dis_hz(90,getmaxy()-28,menuframe[which].submenu[subwhich],WHITE);
sleft=menuframe[which].left;stop=menuframe[which].top;
zwidth=sleft+(strlen(menuframe[which].menuname)+2)*8;
swidth=sleft+(menuframe[which].width+2)*8+10;
scount=menuframe[which].count;atop=stop+30;
for (i=0;i<scount;i++) atop=(strcmp("-",menuframe[which].submenu[i])==0)?atop+10:atop+30;
size=imagesize(sleft,stop,((swidth>zwidth)?swidth:zwidth)+(which==2?2:12),atop+stop);
if (size!=-1) buffer=malloc(size);
if (keylr==0||change==2||(buffer&&(keylr==LEFT||keylr==RIGHT)))
{ getimage(sleft,stop,((swidth>zwidth)?swidth:zwidth)+(which==2?2:12),atop+stop,buffer);change=0; }
Tbutton(sleft,stop,zwidth,stop+19,diy_mgkcolor,diy_mgcolor,menuframe[which].menuname,0,diy_style);
Tbutton(sleft+4,stop+30,swidth+7,atop+15,diy_bkcolor,diy_color,NULL,0,diy_style);
ptop=stop+40;
for (i=0;i<scount;i++)
{ if (strcmp("-",menuframe[which].submenu[i])==0)
{ Tline(sleft+8,ptop+3,swidth+5,ptop+3); ptop+=10;}
else
{ if (subwhich==i) Tbutton(sleft+13,ptop,sleft+25+(menuframe[which].width)*8,ptop+22,diy_sgkcolor,diy_sgcolor,menuframe[which].submenu[i],0,diy_style);
else Tbutton(sleft+13,ptop,sleft+25+(menuframe[which].width)*8,ptop+22,diy_bkcolor,diy_color,menuframe[which].submenu[i],0,diy_style);
ptop+=30; }
}
switch (keylr=inkey())
{ case Alt_X: quit();break;
case F1 : help();break;
case ESC: which=-1;break;
case LEFT: which=which==0?MAX_FRAME-1:which-1;subwhich=0;listtopmenu();break;
case RIGHT: which=which==MAX_FRAME-1?0:which+1;subwhich=0;listtopmenu();break;
case UP: subwhich=(subwhich==0)?scount-1:subwhich-1;
if (strcmp(menuframe[which].submenu[subwhich],"-")==0) subwhich--;break;
case DOWN: subwhich=(subwhich==scount-1)?0:subwhich+1;
if (strcmp(menuframe[which].submenu[subwhich],"-")==0) subwhich++;break;
case ENTER:
clear();
if (which==0)
{ if (subwhich==0) openfile();
if (subwhich==1) list_db_structure();
if (subwhich==2) list_db_recorder();
if (subwhich==3) db_search();
if (subwhich==4) closefile();
if (subwhich==6) quit();
}
if (which==1)
if (subwhich==5) {system("fpk");cleardevice();setmenu();}
else draw(subwhich+1);
if (which==2)
{ if (subwhich==0) set_bkcolor();
if (subwhich==1) set_color();
if (subwhich==2) set_mcolor();
if (subwhich==3) set_scolor();
if (subwhich==5) set_fillstyle();
if (subwhich==6) set_filluser();
}
if (which==3)
{ if (subwhich==0) {system("maze");cleardevice();setmenu();}
if (subwhich==1) message(menuframe[which].submenu[subwhich]);
if (subwhich==2) playmusic();
if (subwhich==4) reset();
if (subwhich==5) help();
if (subwhich==6) welcome();
}
clear();
}
if (buffer&&(keylr==LEFT||keylr==RIGHT)) {putimage(sleft,stop,buffer,COPY_PUT);clear();}
free(buffer);
if (change==1) {listtopmenu();clear();change=2;}
if (which<0) { listtopmenu();clear();break; }
}
return 0;
}
int inkey(void)
{int key;
while(bioskey(1)==0) display_time(400,getmaxy()-50,WHITE);
key=bioskey(0);
key=key&0xff?key&0xff:key>>8;
return (key);
}