错哪了?
在 TC2.0下运行,可是功能不能实现啊!#include <stdio.h>
#include <conio.h>
#include <bios.h>
#define NULL 0
typedef struct menu
{
int ID;
int x;
int y;
int active;
char content[20];
struct menu *pSubMenu;
int n_SubMenu;
}MENU;
#define FILE 1
#define EDIT 2
#define SORT 3
#define FILTER 4
#define HELP 5
#define FILE_NEW 11
#define FILE_OPEN 12
#define FILE_SAVE 13
#define FILE_SAVEAS 14
#define FILE_CLOSE 15
#define FILE_EXIT 16
#define EDIT_ADD 21
#define EDIT_DEL 22
#define EDIT_MOD 23
#define SORT_NUM 31
#define SORT_NAME 32
#define FILTER_NUM 41
#define FILTER_NAME 42
#define FILTER_NEW 43
#define HELP_HELP 51
#define HELP_ABOUT 52
MENU FileSub[6]={
{FILE_NEW,1,2,1,"New",NULL,0},
{FILE_OPEN,1,3,0,"Open",NULL,0},
{FILE_SAVE,1,4,0,"Save",NULL,0},
{FILE_SAVEAS,1,5,0,"Save As",NULL,0},
{FILE_CLOSE,1,6,0,"Close",NULL,0},
{FILE_EXIT,1,7,0,"Exit",NULL,0}
};
MENU EditSub[3]={
{EDIT_ADD,15,2,1,"Add",NULL,0},
{EDIT_DEL,15,3,0,"Delete",NULL,0},
{EDIT_MOD,15,4,0,"Modify",NULL,0}
};
MENU SortSub[2]={
{SORT_NUM,30,2,1,"Number",NULL,0},
{SORT_NAME,30,3,0,"Name",NULL,0}
};
MENU FilterSub[3]={
{FILTER_NUM,45,2,1,"Number",NULL,0},
{FILTER_NAME,45,3,0,"Name",NULL,0},
{FILTER_NEW,45,4,0,"New",NULL,0}
};
MENU HelpSub[2]={
{HELP_HELP,60,2,1,"Help",NULL,0},
{HELP_ABOUT,60,3,0,"About",NULL,0}
};
MENU MainMenu[5]={
{FILE,1,1,0,"File",FileSub,6},
{EDIT,15,1,0,"Edit",EditSub,3},
{SORT,30,1,0,"Sort",SortSub,2},
{FILTER,45,1,0,"Fileter",FilterSub,3},
{HELP,60,1,0,"Help",HelpSub,2}
};
void MenuDraw(MENU *pMenu,int n)
{
window(1,1,80,25);
for(;n>0;n--)
{
textbackground(pMenu->active?BLUE:WHITE);
textcolor(RED);
gotoxy(pMenu->x,pMenu->y);
cprintf("%s",pMenu->content);
pMenu++;
}
}
void FrameDraw()
{
int i,j;
textbackground(BLACK);
clrscr();
window(1,1,80,25);
textbackground(WHITE);
clrscr();
window(1,25,80,25);
clrscr();
textbackground(CYAN);
textcolor(BLACK);
window(1,2,80,2);
clrscr();
window(1,24,80,24);
clrscr();
window(1,2,1,24);
clrscr();
window(80,2,80,24);
clrscr();
window(1,1,80,25);
for(i=2;i<80;i++)
{
gotoxy(i,2);
cprintf("%c",205);
gotoxy(i,24);
cprintf("%c",205);
}
for(j=3;j<24;j++)
{
gotoxy(1,j);
cprintf("%c",186);
gotoxy(80,j);
cprintf("%c",186);
}
gotoxy(1,2);cprintf("%c",201);
gotoxy(80,2);cprintf("%c",187);
gotoxy(1,24);cprintf("%c",200);
gotoxy(80,24);cprintf("%c",188);
textbackground(WHITE);
window(2,3,4,23);
clrscr();
textbackground(BLACK);
window(5,3,54,23);
clrscr();
textbackground(YELLOW);
window(56,3,79,12);
clrscr();
textbackground(BLUE);
window(56,14,79,23);
clrscr();
window(1,1,80,25);
textcolor(BLACK);
textbackground(CYAN);
for(j=3;j<24;j++)
{
gotoxy(55,j);
cprintf("%c",186);
}
for(i=56;i<80;i++)
{
gotoxy(i,13);
cprintf("%c",205);
}
gotoxy(55,2);cprintf("%c",203);
gotoxy(55,24);cprintf("%c",202);
gotoxy(55,13);cprintf("%c",204);
gotoxy(80,13);cprintf("%c",185);
gotoxy(21,2);cprintf("Student List");
gotoxy(60,2);cprintf("Filter Information");
gotoxy(60,13);cprintf("Input Information");
gotoxy(4,3);cprintf("No.");
gotoxy(14,3);cprintf("Name");
gotoxy(30,3);cprintf("Age");
gotoxy(35,3);cprintf("Address");
MenuDraw(MainMenu,5);
}
#define UP_KEY 0x4800
#define DOWN_KEY 0x5000
#define LEFT_KEY 0x4b00
#define RIGHT_KEY 0x4d00
#define F10_KEY 0x4400
#define RETURN_KEY 0x1c0d
#define BS_KEY 0x0e08
#define ESC_KEY 0x011b
int MenuSelect()
{
int b_Exit=0;
int result=0;
int b_SubMenu=0;
int left=1,top=1,right=1,bottom=1,n;
char buffer[500];
MainMenu[0].active=1;
MenuDraw(MainMenu,5);
while(!b_Exit)
{
switch(bioskey(0))
{
case F10_KEY:
if(b_SubMenu)
{
b_SubMenu=0;
puttext(left,top,right,bottom,buffer);
}break;
case ESC_KEY:
n=SearchActiveMenu(MainMenu,5);
MainMenu[n].active=0;
if(b_SubMenu)
{
puttext(left,top,right,bottom,buffer);
}
MenuDraw(MainMenu,5);result=0;b_Exit=1;break;
case UP_KEY:
if(b_SubMenu)
{
int m;
n=SearchActiveMenu(MainMenu,5);
m=SearchActiveMenu(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
(MainMenu[n].pSubMenu+m)->active=0;
if(m==0)
{
(MainMenu[n].pSubMenu+MainMenu[n].n_SubMenu-1)->active=1;
}
else
{
(MainMenu[n].pSubMenu+m-1)->active=1;
}
MenuDraw(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
}break;
case DOWN_KEY:
if(b_SubMenu)
{
int m;n=SearchActiveMenu(MainMenu,5);
m=SearchActiveMenu(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
(MainMenu[n].pSubMenu+m)->active=0;
if(m==(MainMenu[n].n_SubMenu-1))
{
MainMenu[n].pSubMenu->active=1;
}
else
{
(MainMenu[n].pSubMenu+m+1)->active=1;
}
MenuDraw(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
}break;
case LEFT_KEY:
n=SearchActiveMenu(MainMenu,5);
MainMenu[n].active=0;
n=(n==0)?4:(n-1);
MainMenu[n].active=1;
MenuDraw(MainMenu,5);
if(b_SubMenu)
{
puttext(left,top,right,bottom,buffer);
left=MainMenu[n].pSubMenu->x;
top=2;
right=left+20;
bottom=top+MainMenu[n].n_SubMenu-1;
gettext(left,top,right,bottom,buffer);
window(left,top,right,bottom);
textbackground(WHITE);
clrscr();
MenuDraw(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
}break;
case RIGHT_KEY:
n=SearchActiveMenu(MainMenu,5);
MainMenu[n].active=0;
n=(n+1)%5;
MainMenu[n].active=1;
MenuDraw(MainMenu,5);
if(b_SubMenu)
{
puttext(left,top,right,bottom,buffer);
left=MainMenu[n].pSubMenu->x;
top=2;right=left+20;
bottom=top+MainMenu[n].n_SubMenu-1;
gettext(left,top,right,bottom,buffer);
window(left,top,right,bottom);
textbackground(WHITE);
clrscr();
MenuDraw(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
}break;
case RETURN_KEY:
n=SearchActiveMenu(MainMenu,5);
if(!b_SubMenu)
{
b_SubMenu=1;
left=MainMenu[n].pSubMenu->x;
top=2;right=left+20;
bottom=top+MainMenu[n].n_SubMenu-1;
gettext(left,top,right,bottom,buffer);
window(left,top,right,bottom);
textbackground(WHITE);
clrscr();
MenuDraw(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
}
else
{
int m;
m=SearchActiveMenu(MainMenu[n].pSubMenu,MainMenu[n].n_SubMenu);
result=(MainMenu[n].pSubMenu+m)->ID;
MainMenu[n].active=0;
puttext(left,top,right,bottom,buffer);
MenuDraw(MainMenu,5);
b_Exit=1;
}
}break;
}return(result);
}
int SearchActiveMenu(MENU *pMenu,int n)
{
for(n--;n>=0;n--)
{
if(pMenu[n].active) break;
}return(n);
}
main()
{
int b_Exit=0;
/*textmod(C80);*/
textbackground(BLACK);
textcolor(WHITE);
clrscr();
FrameDraw();
while(!b_Exit)
{
switch(bioskey(0))
{
case F10_KEY:
if(MenuSelect()==FILE_EXIT)
b_Exit=1;
case UP_KEY:
case DOWN_KEY:break;
}
}
}