#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <stdio.h>
/*定义各个按键的值*/
#define fRIGHT 0x4d00
#define fENTER 0x000d
#define fLEFT 0x4b00
#define fUP 0x4800
#define fDOWN 0x5000
#define fESC 0x001b
#define fTAB 0x0009
#define fINSERT 0x5200
#define fHOME 0x4700
#define fEND 0x4f00
#define fPageUp 0x4900
#define fPageDown 0x5100
#define fDEL 0x5300
#define fF1 0x3b00
#define fF2 0x3c00
#define fF3 0x3d00
#define fF4 0x3e00
#define fF5 0x3f00
#define fF6 0x4000
#define fF7 0x4100
#define fF8 0x4200
#define fF9 0x4300
#define fF10 0x4400
#define mcolor BLUE /*定义字体颜色*/
/*设置图形配置器,如果图形配置器设置不对,在此函数中修改*/
void setgraph(void)
{int gd=DETECT,gm=0;
registerbgidriver(EGAVGA_driver);
initgraph(&gd,&gm,"");
}
/*链表数据区*/
struct record
{
char stuid[10]; /*学号*/
char name[30]; /*姓名*/
char chinese[5]; /*语文*/
char math[5]; /*数学*/
char english[5]; /*英语*/
char chemistry[5];/*化学*/
char computer[5]; /*电脑*/
char music[5]; /*音乐*/
char picture[5]; /*美术*/
char physics[5]; /*物理*/
char sport[5]; /*体育*/
struct record *next; /*上一个数据地址*/
struct record *prior; /*下一个数据地址*/
}list_entry;
/*___________*/
/*菜单数据区*/
struct record *start; /*用来存储上一个地址值*/
struct record *last; /*用来存储下一个地址值*/
void *buf;/*用来保存图象数据的指针*/
char title[]="Student Restul Inquire System. Ver 1.0";/*标题栏文字---学生成绩查询系统*/
char menutext[8][20]={/*菜单栏文字*/
"Files","Edits","","","","","",""};
int menutextcolor[8]={7,7,7,7,7,7,7,7}; /*菜单栏文字颜色控制,用来显示被选中的菜单*/
char list[8][5][20]={/*菜单选项文字*/
".About",".Cls",".LoadFile",".SaveFile",".Quit",/*介绍,清屏,读档案文件,写档案文件,退出*/
".New",".Delete",".List",".Search",".Revise",/*新建,删除,列表,搜索,修改*/
".",".",".",".",".",
".",".",".",".",".",
".",".",".",".",".",
".",".",".",".",".",
".",".",".",".",".",
".",".",".",".",".",
};
/*各个菜单选项区大小分配*/
int x1=495,y1=60,x2=635,y2=175;
int xs1[8]={10,85,163,240,320,400,480,485};
int xs2[8]={150,225,303,380,460,540,620,635};
/*___________*/
char filename[30]; /*文件名*/
/*链表函数区*/
void enter(); /*新创建一个数据,也就是学生的学号、姓名和各科成绩*/
void display(); /*显示数据内容*/
void search(); /*搜索数据,有两种查找模式,学号和姓名*/
void save(); /*保存数据到文件中*/
void load(); /*从文件中读取数据到内存*/
void revise(); /*修改数据*/
void getname(int ,int ,char *);/*一个在图形界面下输入字符的函数*/
/*____________*/
/*菜单函数区*/
int Funkey(); /*无暂停按键判断*/
int OneFunKey(); /*有暂停按键判断*/
void setgraph(); /*显示器设置,如果你不能正常运行,请修改这个程序*/
void ShowMenu(); /*显示菜单轮廓*/
void ShowList(int x); /*显示选项框*/
void SaveList(); /*选项框显示区图象保存*/
void PutListSave(); /*选项框显示区图象释放*/
void MenuLight(int keydat); /*菜单字幕变色,表示该栏菜单被选中*/
void ListLight(int m); /*选项字幕变色,表示光条在该选项上*/
void IDmaster(int id); /*选项编号管理器,用来确定哪个选项被选中*/
void MenuMaster(); /*菜单按键管理器,用来判断方向键等*/
void aboutme(); /*介绍自己以及论坛*/
/*___________*/
main() /*主函数*/
{
unsigned key;
int n;
filename[0]='\0'; /*初始化文件名,在SAVE中判断是否已经输入过文件名,如果没有,重新输入*/
setgraph();
ShowMenu();
buf=(void *)malloc(imagesize(x1,y1,x2,y2));
while((key=FunKey())!=255){ /*判断是否激活了菜单*/
setcolor(7);
rectangle(5,20,79*8,40);
if(key==fTAB){ /*按下TAB键激活菜单*/
setcolor(YELLOW);
rectangle(5,20,79*8,40);
MenuMaster();
}
}
getch();
}
void aboutme() /*介绍自己以及论坛*/
{
void *mpbuf;
mpbuf=(void *)malloc(imagesize(200,200,400,300));
getimage(200,200,400,300,mpbuf);
setfillstyle(SOLID_FILL,BLUE);
bar(200,200,400,300);
setcolor(RED);
outtextxy(240,235," vLinux");
outtextxy(210,280,"By http://bbs.bc-cn.net");
getch();
putimage(200,200,mpbuf,0);
free(mpbuf);
}
/*无暂停按键控制器*/
int FunKey()
{
unsigned key;
if(bioskey(1)==0)
return(0);
key=bioskey(0);
if(key<<8)
key=key&0x00ff;
return key;
}
/*有暂停按键控制器*/
int OneFunKey()
{
unsigned key;
key=bioskey(0);
if(key<<8)
key=key&0x00ff;
return key;
}
void ShowMenu()/*画菜单轮廓*/
{
int n;
/*标题栏*/
setfillstyle(SOLID_FILL,BLUE);
bar(0,0,639,20);
/*菜单栏*/
setfillstyle(SOLID_FILL,8);
bar(5,20,79*8,40); /*菜单栏背景*/
setcolor(0);
for(n=1;n<=8;n++)
rectangle(5,20,79*n,40);
/*工作区*/
setfillstyle(SOLID_FILL,7);
bar(6,45,635,475);
/*重新标绘边框*/
setcolor(7);
rectangle(0,0,639,479);
/*菜单文字信息*/
/*标题栏文字*/
settextstyle(0,0,2);
outtextxy(2,2,title);
/*菜单栏文字*/
settextstyle(0,0,1);
for(n=0;n<8;n++){
setcolor(menutextcolor[n]);
outtextxy(20+n*80,25,menutext[n]);
}
}
/*菜单选项*/
void ShowList(int x)
{
int m,n,a=x1,b=y1,c=x2,d=y2;
/*进行文字阴影处理*/
for(n=0;n<3;n++){
setcolor(8+n);
for(m=0;m<5;m++){
rectangle(a,b,c,d-(d-b)/5*m);
outtextxy(a+8,(b+8)+(d-b)/5*m,menutext[x]);
outtextxy(a+8+sizeof(menutext[x])*2,(b+8)+(d-b)/5*m,list[x][m]);
}
a++;b++;c--;d--;
}
}
void clsworkplace() /*清除工作区*/
{
setfillstyle(SOLID_FILL,7);
bar(6,45,635,475);
}
void clstextlen() /*清除消息显示区,用来更新消息文字*/
{
setfillstyle(SOLID_FILL,7);
bar(10,60,250,67);
}
void SaveList()/*保存菜单选项显示区*/
{
getimage(x1,y1,x2,y2,buf);
}
void PutListSave() /*释放菜单选项显示区*/
{
putimage(x1,y1,buf,0);
}
void MenuLight(int keydat)/*菜单被选中的栏用高亮度显示*/
{
int n;
for(n=0;n<8;n++)
menutextcolor[n]=7;
if(0<=keydat<=7)
menutextcolor[keydat-1]=YELLOW;
for(n=0;n<8;n++){
setcolor(menutextcolor[n]);
outtextxy(20+n*80,25,menutext[n]);
}
}
void ListLight(int m) /*菜单选项的光条,采用改变背景颜色重放技术*/
{
int a=x1,b=y1,c=x2,d=y2;
setfillstyle(SOLID_FILL,13);
bar(a,b-(d-b)/5*(m-4),c,d-(d-b)/5*m);
}
void MenuMaster() /*菜单按键管理器*/
{
unsigned key;
int Lsign,x=-1,y=-1,id=-1,sign=0;/*sign为IDmaster标记,如果sign=1则跳出while去执行IDmaster*/
Lsign=0;/*功能按贱执行标记,0-没执行,1-执行了*/
SaveList();/*保存菜单选项区的图象*/
while(sign==0 && (key=OneFunKey())!=fTAB){
switch(key){/*功能按键*/
case fLEFT: x--;break;
case fRIGHT: x++;break;
case fUP: y++;break;
case fDOWN: y--;break;
case fESC: PutListSave();MenuLight(9);break;
case fENTER: id=(10*(x+1)+5-y);sign=1;break;/*计算ID的值,并且sign标志为1*/
}
/*限制上下左右的范围*/
if(x<0) x=1;
if(x>1) x=0;
if(y<0) y=4;
if(y>4) y=0;
PutListSave();/*释放保存的图象数据,起清除原来的菜单选项图象作用*/
x1=xs1[x];x2=xs2[x];
SaveList(); /*保存新的菜单选项区的图象数据*/
ListLight(y); /*显示光条*/
ShowList(x); /*显示菜单选项*/
MenuLight(x+1); /*加亮被选中的菜单名称*/
Lsign=1;/*把标志设置成1,表示已经执行过了*/
}
/*如果Lsign标志为1,那么执行下面的代码。作用是,返回保存的单选项显示区图象数据*/
if(Lsign){
PutListSave();
MenuLight(9);
}
IDmaster(id);/*把ID的值送给IDmaster*/
}
void enter() /*输入学生档案信息函数*/
{
int c=0;
struct record *info,*dls_store();
setfillstyle(SOLID_FILL,7);
bar(330,70,630,478);
for(;c<1;c++){
info=(struct record *)malloc(sizeof(list_entry));
if(!info){
clstextlen();
outtextxy(10,60,"out of memory");
return;
}
for(c=0;c<11;c++){ /*画表格*/
setcolor(BLUE);
rectangle(320,70,586,90+20*c);
}
inputs(334,75,"enter student ID:",500,75,info->stuid,10);
if(!info->stuid[0])
break;
inputs(334,75+20*1,"enter name: ",500,75+20*1,info->name,30);
inputs(334,75+20*2,"enter Chinese: ",500,75+20*2,info->chinese,5);
inputs(334,75+20*3,"enter Math: ",500,75+20*3,info->math,5);
inputs(334,75+20*4,"enter English: ",500,75+20*4,info->english,5);
inputs(334,75+20*5,"enter Chemistry: ",500,75+20*5,info->chemistry,5);
inputs(334,75+20*6,"enter Physics: ",500,75+20*6,info->physics,5);
inputs(334,75+20*7,"enter Computer: ",500,75+20*7,info->computer,5);
inputs(334,75+20*8,"enter Music: ",500,75+20*8,info->music,5);
inputs(334,75+20*9,"enter Picture: ",500,75+20*9,info->picture,5);
inputs(334,75+20*10,"enter sport: ",500,75+20*10,info->sport,5);
start=dls_store(info,start);
clstextlen();
outtextxy(10,60,"Input is END!");
}
}
inputs(xo,yo,prompt,xi,yi,s,count) /*输入函数*/
/*(xo,yo)显示文字坐标,显示文字内容,(xi,yi)输入文字坐标,输入文字的最大值*/
char *prompt;
char *s;
int xi,yi,xo,yo,count;
{
int n;
char p[255];
setcolor(mcolor);
clstextlen(); /*清除信息区域*/
do{
for(n=0;n<=200;n++) p[n]='\0';
outtextxy(xo,yo,prompt);
getname(xi,yi,p);
if(strlen(p)>count){ /*判断输入的数据是否超过范围,这样可以防止溢出攻击*/
clstextlen();
outtextxy(10,60,"too long");
}
}while(strlen(p)>count);
strcpy(s,p);
}
struct record *dls_store(i,top) /*双链表连接函数*/
struct record *i;
struct record *top;
{
struct record *old,*p;
if(last==NULL){
i->next=NULL;
i->prior=NULL;
last=i;
return i;
}
p=top;
old=NULL;
while(p){
if(strcmp(p->name,i->name)<0){
old=p;
p=p->next;
}
else{
if(p->prior){
p->prior->next=i;
i->next=p;
i->prior=p->prior;
p->prior=i;
return top;
}
i->next=p;
i->prior=NULL;
p->prior=i;
return i;
}
}
old->next=i;
i->next=NULL;
i->prior=old;
last=i;
return start;
}
delete() /*删除选定的学生档案,输入学号确定学生*/
{
struct record *info,*find();
static char s[10];
int n;
for(n=0;n<10;n++)
s[n]='\0';