#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
/*定义各键的bioskey(0)的按键返回值*/
#define Key_DOWN 0x5000
#define Key_UP 0x4800
#define Key_A 0x1e41
#define Key_a 0x1e61
#define Key_B 0x3042
#define Key_b 0x3062
#define Key_C 0x2e43
#define Key_c 0x2e63
#define Key_E 0x1245
#define Key_e 0x1265
#define Key_ENTER 0x1c0d
/*用户选择的行,缺省为0*/
int activeline=0;
/*存储用户选择区*/
char buf[8*4*2];
/*用来激活用户选择的行*/
void modicolor(char *buf,int active)
{ int red=(WHITE+(RED<<4)); /*红底白字*/
int white=(WHITE+(BLUE<<4)); /*蓝底白字*/
int i=1;
while(i<=63)
{
if (i/16==active){
if ((i%2)!=0)
*(buf+i)=red;
}
else if((i%2)!=0)
*(buf+i)=white;
i+=2;
}
activeline=active;
puttext(9,10,16,13,buf);
}
int main()
{
int ky=0;
char ch;
textattr(WHITE+(BLACK<<4));
clrscr();
textmode(C80);
textattr(RED+(5<<4));
window(7,8,19,15); /*生成一个洋红色窗口*/
clrscr();
textattr(WHITE+(BLUE<<4));
window(8,9,18,14); /*洋红色窗口内嵌一个蓝色窗口*/
clrscr();
gotoxy(3,2);
cprintf("E:exit");
gotoxy(3,3);
cprintf("A:dir");
gotoxy(3,4);
cprintf("B:dir/p");
gotoxy(3,5);
cprintf("C:dir/w\r\n");
gettext(9,10,16,13,buf);
modicolor(buf,0);
while(ky!=Key_E && ky!=Key_e)
{
ky=bioskey(0);
switch(ky)
{
case Key_UP:
if (activeline==0){
modicolor(buf,3);
break;
}
if (activeline!=0){
modicolor(buf,--activeline);
break;
}
case Key_DOWN:
if (activeline==3){
modicolor(buf,0);
break;
}
if (activeline!=3){
modicolor(buf,++activeline);
break;
}
case Key_ENTER:
if (activeline==0) exit(0);
if (activeline==1) goto dir;
if (activeline==2) goto dirp;
if (activeline==3) goto dirw;
case Key_A:
case Key_a:
dir: system("dir");
getch();
modicolor(buf,activeline);
break;
case Key_B:
case Key_b:
dirp: system("dir /p");
getch();
modicolor(buf,activeline);
break;
case Key_C:
case Key_c:
dirw: system("dir /w");
getch();
modicolor(buf,activeline);
break;
}
}
}