求助!!!会屏幕处理函数的请进!!
谢谢,有那个会的帮个忙吧!!!
如何使程序实现以下功能:
1.增加
2.删除
3.....
4.....
在屏幕上显示菜单,并能通过键盘来选择菜单,而且能通过enter来选择选项
问题点数:0、回复次数:4Top
1 楼eshowjow(Ж※★※Ж)回复于 2004-05-03 20:53:26 得分 0
在屏幕输出 1.增加
2.删除
3.....
4.....
switch(变量)
case 1:增加功能
case 2:删除功能
……
Top
2 楼Cathryn0000000(苹果雹冰oοО)回复于 2004-05-03 21:28:42 得分 0
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.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 xx,int yy,int hight,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[]={"New ",
"Open ",
"Print ",
"Zoom ",
"Quit ",};
char buf[16*10*2],buf1[16*2];
textbackground(1);
clrscr();
textmode(C80);
window(1,1,80,1);
textbackground(15);
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);}
while(1)
{
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(4,1);
cprintf("%s",menu[0]);
gettext(4,2,19,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,12,buf);
textbackground(15);
textcolor(0);
gotoxy(4,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 xx,int yy,int hight,int width)
{int i;
gotoxy(xx,yy);
putch(0xda);
for(i=xx+1;i<width;i++)
putch(0xc4);
putch(0xbf);
for(i=yy+1;i<hight;i++)
{gotoxy(xx,i);putch(0xb3);
gotoxy(width,i);putch(0xb3);
}
gotoxy(xx+1,width);
putch(0xc0);
for(i=xx+1;i<width;i++) putch(0xc4);
putch(0xd9);
return;
}
Top
3 楼cngdzhang()回复于 2004-05-03 21:35:07 得分 0
我编写了一个tc下的
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void printmenu(int sel)
{
char menu[][100]={"1.menu1","2.menu2","3.menu3","4.menu4"};
int i;
for(i=0;i<4;i++)
{
textcolor(15);
if(i==sel) textbackground(7);
else textbackground(0);
gotoxy(1,i+1);
cprintf("%s",menu[i]);
}
}
void main()
{
char c;
int sel=0;
clrscr();
printmenu(sel);
while(1)
{
if(kbhit())
{
c=getch();
if(c==0) c=getch(); //如果是控制键
if(c==80) sel=(sel+1)%4; //向下
if(c==72) sel=(sel+4-1)%4; //向上
if(c=='\r') break;
printmenu(sel);
}
}
switch(sel)
{
case 0:
printf("\nYou sel menu1\n");
break;
case 1:
printf("\nYou select menu2\n");
break;
case 2:
printf("\nYou select menu3\n");
break;
case 3:
printf("\nYou select menu4\n");
break;
default:
printf("Error\n");
break;
}
}Top
4 楼skycncomp(闭关修练到年底)回复于 2004-05-03 21:48:22 得分 0
多看看C语言编程宝典,挺不错的。
自己慢慢来。干嘛要别人编帮编。网上便子好多的。
google一下>10000Top




