您现在的位置:计算机技术学习网 > 技术中心 > 编程开发 > C >

c语言课程设计_下拉菜单程序

来源:不详 责任编辑:栏目编辑 发表时间:2013-07-01 05:42 点击:

#include <process.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define key_down 80
#define key_up 72
#define key_esc 1
#define key_alt_f 33
#define key_alt_x 45
#define key_enter 28

int get_key();
void box(int startx,int stary,int high,int width);
main()
{
int i,key,x,y,l;
char *menu[]={"File","Edit","Run","Options","Help","Setup","Zoom","Menu"};
char *red[]={"F","E","R","O","H","S","Z","M"};
char *f[]={"Load file", "Save file","Print ","Modify ",
"Quit alt_x "};
char buf[16*10*2],buf1[16*2];
while(1)
{
textbackground(1);
clrscr();
window(1,1,80,1);
textbackground(15);
textcolor(0);
clrscr();
window(1,1,80,2);
for(i=0,l=0;i<8;i++)
{
x=wherex();
y=wherey();
cprintf(" %s",menu[i]);
l=strlen(menu[i]);
gotoxy(x,y);
textcolor(RED);
cprintf(" %s",red[i]);
x=x+l+4;
gotoxy(x,y);
textcolor(BLACK);
}
x=0;
key=0;
while (bioskey(1)==0);
key=get_key();
if(key==key_alt_x)exit(0);
if(key==key_alt_f)
{
textbackground(0);
textcolor(15);
gotoxy(2,1);
cprintf("%s",menu[0]);
gettext(4,2,18,12,buf);
window(4,2,19,8);
textbackground(15);
textcolor(0);
clrscr();
window(4,2,19,9);
box(1,1,7,16);
for(i=2; i<7;i++)
{
gotoxy(2,i);
cprintf("%s",f[i-2]);
}
gettext(2,2,18,3,buf1);
textbackground(0);
textcolor(15);
gotoxy(2,2);
cprintf("%s",f[0]);
y=2;
key=get_key();
while(key!=key_alt_x&&key!=key_enter&&key!=key_esc)
{
if(key==key_up||key==key_down)
{
puttext(2,y,18,y+1,buf1);
if(key==key_up)
y=y==2? 6:y-1;
if(key==key_down)
y=y==6? 2:y+1;
gettext(2,y,18,y+1,buf1);
textbackground(0);
textcolor(15);
gotoxy(2,y);
cprintf("%s",f[y-2]);
}
key=get_key();
}
if(key==key_alt_x)
exit(0);
if(key==key_enter)
{
switch(y-1)
{
case 1: break;
case 2: break;
case 3: break;
case 4: break;
case 5: exit(0);
default: break;
}
}
else
{window(1,1,80,2);
puttext(4,2,19,10,buf);
textbackground(15);
textcolor(0);
gotoxy(2,1);
cprintf("%s",menu[0]);
}
}
}
}

int get_key()
{
union REGS rg;
rg.h.ah=0;
int86(0x16,&rg,&rg);
return rg.h.ah;
}

void box(int startx,int starty,int high,int width)
{
int i;
gotoxy(startx,starty);
putch(0xda);
for (i=startx+1;i<width;i++)
putch(0xc4);
putch(0xbf);
for(i=starty+1;i<high;i++)
{
gotoxy(startx,i);
putch(0xb3);
gotoxy(width,i);
putch(0xb3);
}
gotoxy(startx+1,width);
putch(0xc0);
for(i=startx+1;i<width;i++)
putch(0xc4);
putch(0xd9);
return;
}

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1