/* MENUE.C 西文DOS下的西文下拉式菜单 */ #include "graphics.h" #include "conio.h" #include "bios.h" #include "process.h" #include "string.h" #include "stdio.h"
#define LEFT 331 /* 功能键的宏定义 */ #define RIGHT 333 #define UPPER 328 #define DOWN 336 #define ALT_X 301 #define ESC 27 #define ENTER 13
void WrtMnMenu(void); void WrtSbMenu(void); void SlctMenu(void); void SlctMnMenu(void); void SlctSbMenu(void); int GetKey(void); void SbFunGo(void); void Screen(void); void Wind(int,int,int,int,int,int,int,int,int); void Quit(void);
int Mm = 0; /* 主菜单选项 */ int Smm[4]; /* 各项主菜单下的子菜单选项 */ int SbNum[4] = {6, 6, 4, 3}; /* 各项主菜单的子菜单项数 */ int SbWid[4] = {20, 10, 13, 16}; /* 各项子菜单的窗口宽度 */ int SbX[4] = {5, 20, 33, 47}; /* 各项子菜单的X坐标 */ int Key = 0; /* 选择的键 */ char Buf[1000]; char *Main[4] = {" Parameters ", " Sampling ", " Reduction ", " Simple "}; /* 主菜单项名 */ char *Sub[4][6] = { { "Signal Channel", /* 子菜单项名 */ "Channel Selected", "Sample Points", "Sample Friquency", "Amplifyer Gain", "Trigger signal" }, { "Sampling ", "Dataview ", "Waveview ", "Realtime ", "Histogram", "Realhisto" }, { "Reduction ", "Resultdata ", "Resultview ", "Calibration" }, { "Acceleration 1", "Acceleration 2", "Acceleration 3" }}; int main(void) { Screen(); WrtMnMenu(); WrtSbMenu(); SlctMenu(); Quit(); return(0); }
void WrtMnMenu(void) { int i; window(1, 1, 80, 25); /* 显示主菜单 */ textattr(0x3e); for (i = 0; i < 4; i++) { gotoxy(SbX[i], 1); cputs(Main[i]); } gotoxy(SbX[Mm], 1); /* 设置光条颜色 */ textattr(0x4e); cputs(Main[Mm]); }
void WrtSbMenu(void) { int i; gettext(SbX[Mm]-2, 2, SbX[Mm]+SbWid[Mm]+1, SbNum[Mm]+4, Buf); Wind(SbX[Mm]-2, 2, SbX[Mm]+SbWid[Mm], SbNum[Mm]+3, 1, 1, 3, 15, 1); textattr(0x3f); /* 显示子菜单 */ for (i=0; i < SbNum[Mm]; i++) { gotoxy(2, 1+i); cputs(Sub[Mm][i]); } textattr(0x1e); /* 子菜单选项的颜色 */ gotoxy(2, Smm[Mm]+1); cputs(Sub[Mm][Smm[Mm]]); }
void SlctMenu(void) /* 执行菜单选择功能 */ { while(Key != ALT_X && Key != ESC) { Key = GetKey(); if (Key == LEFT || Key == RIGHT) SlctMnMenu(); if (Key == UPPER || Key == DOWN) SlctSbMenu(); if (Key == ENTER) SbFunGo(); } return; }
void SlctMnMenu(void) { window(1, 1, 80, 25); textattr(0x3e); gotoxy(SbX[Mm], 1); cputs(Main[Mm]); textattr(0x31); puttext(SbX[Mm]-2, 2, SbX[Mm]+SbWid[Mm]+1, SbNum[Mm]+4, Buf); if (Key == LEFT) Mm = Mm == 0 ? 3 : Mm-1; if (Key == RIGHT) Mm = Mm == 3 ? 0 : Mm+1; textattr(0x4e); gotoxy(SbX[Mm], 1); cputs(Main[Mm]); WrtSbMenu(); }
void SlctSbMenu(void) { textattr(0x3f); gotoxy(2, 1+Smm[Mm]); cputs(Sub[Mm][Smm[Mm]]); if (Key == UPPER) Smm[Mm] = Smm[Mm] == 0 ? SbNum[Mm]-1 : Smm[Mm]-1; if (Key == DOWN) Smm[Mm] = Smm[Mm] == SbNum[Mm]-1 ? 0 : Smm[Mm]+1; textattr(0x1e); gotoxy(2, Smm[Mm]+1); cputs(Sub[Mm][Smm[Mm]]); }
int GetKey(void) { int Ch, Low, Hig; Ch = bioskey(0); Low = Ch & 0x00ff; Hig = (Ch & 0xff00) >> 8; return (Low == 0 ? Hig+256 : Low); }
void SbFunGo(void) /* 根据键选执行相应的功能 */ { switch(Mm) { case 0: switch(Smm[0]) { case 0: break; case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; } break; case 1: switch(Smm[1]) { case 0: break; case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; } break; case 2: switch(Smm[2]) { case 0: break; case 1: break; case 2: break; case 3: break; } break; case 3: switch(Smm[3]) { case 0: break; case 1: break; case 2: break; } break; } }
void Screen(void) { window(1, 1, 80, 25); textattr(0x17); clrscr(); window(1, 1, 80, 1); textattr(0x3e); clrscr(); window(1, 24, 80, 24); textattr(0x74); clrscr(); cputs(" \x18 "); /* ↑键 */ cputs("\x19 "); /* ↓键 */ cputs("\x1a "); /* →键 */ cputs("\x1b "); /* ←键 */ textattr(0x7e); cputs("and "); textattr(0x74); cputs("Enter "); textattr(0x7e); cputs("to select menu. "); textattr(0x74); cputs(" Alt_X "); textattr(0x7e); cputs(" or "); textattr(0x74); cputs(" ESC "); textattr(0x7e); cputs(" to quit"); window(1, 25, 80, 25); textattr(0x6A); clrscr(); cputs(" BEIJING AGRICLUTURAL ENGINEERING UNIVERSITY & SHAN DONG COLLGE OF ENGINEERING"); Wind(1, 2, 80, 23, 2, 0, 1, 15, 1); window(1, 1, 80, 25); }
/* 字符窗口函数: x1, y1: 窗口左上角坐标; x2, y2: 窗口右下角坐标; FrmTp: 窗口边框类型: 0--无边框; 1--单线边框; 2--双线边框; IsBk: 是否带阴影背景; BCl: 字符颜色; TCl: 背景颜色; BgCl: 阴影背景的颜色. */ void Wind(int x1,int y1,int x2,int y2,int FrmTp,int IsBk,int BCl,int TCl,\ int BgCl) { int i; int c[2][6]={{0xda, 0xc4, 0xbf, 0xb3, 0xc0, 0xd9}, /* 单线字符 */ {0xc9, 0xcd, 0xbb, 0xba, 0xc8, 0xbc}}; /* 双线字符 */ textcolor(TCl); textbackground(BCl); window(x1, y1, x2, y2); clrscr(); if (FrmTp) /* 有边框线 */ { window(1, 1, 80, 25); gotoxy(x1, y1); putch(c[FrmTp-1][0]); for (i = x1+1; i < x2; i++) putch(c[FrmTp-1][1]); putch(c[FrmTp-1][2]); for (i = y1+1; i < y2; i++) { gotoxy(x1, i); putch(c[FrmTp-1][3]); gotoxy(x2, i); putch(c[FrmTp-1][3]); } gotoxy(x1, y2); putch(c[FrmTp-1][4]); for (i = x1+1; i < x2; i++) putch(c[FrmTp-1][1]); putch(c[FrmTp-1][5]); } if (IsBk) /* 有阴影背景 */ { textcolor(BgCl); textbackground(0); for (i = y1+1; i < y2+1; i++) { gotoxy(x2+1, i); putch('\xb1'); } for (i = x1+1; i < x2+2; i++) { gotoxy(i, y2+1); putch('\xb1'); } } window(x1+1, y1+1, x2-1, y2-1); }
void Quit(void) { textbackground(0); textcolor(7); window(1, 1, 80, 25); clrscr(); exit(0); }