?? tc20寫的dos底下文本菜單.htm
字號:
<P><BR>TC20寫的DOS底下文本菜單<BR><BR><BR>很象用TURBO VISION寫的界面。
<BR><BR>/*<BR><BR>DATE:05/2000<BR>TOPIC:文本菜單<BR>pass by:turboc 20
<BR><BR>*/<BR><BR># include <graphics.h><BR># include
<alloc.h><BR># include <process.h><BR># include
<stdio.h><BR># include <stdlib.h><BR># include
<time.h><BR># include <string.h><BR># include
<dos.h><BR># include <bios.h><BR># include
<conio.h><BR># include <ctype.h><BR><BR># define
SCREENMINX 0<BR># define SCREENMINY 0<BR># define SCREENMAXX 79<BR>#
define SCREENMAXY 24<BR><BR>#define WindowMaxX 79<BR>#define
WindowMinX 0<BR>#define WindowMaxY 24<BR>#define WindowMinY
0<BR><BR>/* #define BLINK 0x80 */<BR>#define LIGHT 0x08<BR>#define
WHITE 0x07<BR>#define BLACK 0x00<BR>#define RED 0x04<BR>#define
GREEN 0x02<BR>#define BLUE 0x01<BR><BR>#define MIXCOLOR(A,B)
A|B<BR>#define LIGHTSHOW(A) A|LIGHT<BR>#define DARKSHOW(A)
A&0xf7<BR>#define BLINKSHOW(A) A|BLINK<BR>#define
NOTBLINKSHOW(A) A&0x7f<BR>#define BACKCOLOR(A)
A<<4<BR>#define MIX(A,B) (A | BACKCOLOR(B))<BR>#define
GetBackColor(A) ((A&0x70)>>4)<BR>#define GetForeColor(A)
A&0x0f<BR>#define EnabledSelectMenuItem
MIX(BLACK,WHITE)<BR>#define EnabledMenuItem
MIX(BLACK,GREEN)<BR>#define DisabledSelectMenuItem
MIX(LIGHSHOW(BLACK),BLACK)<BR>#define DisabledMenuItem
MIX(LIGHSHOW(BLACK),WHITE)<BR><BR><BR># define INSERT 0x5200<BR>#
define ESC 0x001b<BR># define TAB 0x0f09<BR># define RETURN
0x000d<BR># define RIGHT 0x4d00<BR># define LEFT 0x4b00<BR># define
UP 0x4800<BR># define DOWN 0x5000<BR># define BS 0x0e08<BR># define
HOME 0x4700<BR># define END 0x4f00<BR># define PGUP 0x4900<BR>#
define PGDN 0x5100<BR># define DEL 0x5300<BR># define F1 0x3b00<BR>#
define F2 0x3c00<BR># define F3 0x3d00<BR># define F4 0x3e00<BR>#
define F5 0x3f00<BR># define F6 0x4000<BR># define F7 0x4100<BR>#
define F8 0x4200<BR># define F9 0x4300<BR># define F10
0x4400<BR><BR># define MenuInGround 1<BR># define MenuActiveGround
2<BR># define MenuActiveItem 3<BR># define MenuInItem 4<BR># define
MenuEdge 5<BR># define WindowEdge 6<BR># define WindowGround 7<BR>#
define PopWindow 8<BR><BR>/*<BR>unsigned char AllColors[20] = { 0
,CYAN , LIGHTRED , YELLOW ,<BR>BLACK , WHITE ,
LIGHTRED,BLUE,<BR>CYAN ,9 ,10,11 ,12 ,13 ,14,15}
;<BR>*/<BR><BR>typedef unsigned char UCHAR;<BR>typedef unsigned int
UINT;<BR>typedef unsigned long ULONG;<BR><BR>char
edge[7]={0xda,0xc4,0xbf,0xb3,0xd9,0xc0,'\0'};<BR><BR>/* char
edge1[7]={}; */<BR><BR>#define INUM 10 /* R maximum IO itenls in
each MENU w */<BR><BR>typedef struct _menu<BR>{<BR>char coor[4]; /*
The menu's area w */<BR>char itemcoor[4 * INUM]; /* max IO item,
each with xl,yl ,x2,y2 w */<BR>char itemdispxy[2 * INUM] ; /*
Actually disp item name's X coor w */<BR>char select; /* selected
item's ord # */<BR>char itemnum; /* The number of items in this menu
w */<BR>char **itemname; /* w item's name(point to static data) R
*/<BR>int COMMAND_ID[INUM]; /* w Key number R */<BR>}MENUTYPE
;<BR><BR>static char * MainMenuItem[]= {" File "," Edit "," Run ","
Compile "," Help ",<BR>" Exit ", 0 };<BR>static char *Syshelp="
F1-Help F5-Zoom F6-Switch F7-Trace F8-Step F9-Make
F10-Menu";<BR><BR>static char * SubMenuItem1[]= {" Load File... F3
",<BR>" Pick File Alt+F3 ",<BR>" New ",<BR>" Save F2 ",<BR>" Write
to ",<BR>" Os Shell ",<BR>" Quit Alt+X ",0};<BR>/*<BR>static char
*SubMenuItem[6][]={{"Help11..."},<BR>{<BR>*/<BR>static char *
SubMenuItem2[]= {" Item21...",<BR>" Draw ",<BR>" Item23 ",<BR>"
Item24 ",<BR>" Item25 ",<BR>" Item26 ",<BR>" Item27 ",<BR>" Item28
",0};<BR><BR>static char * SubMenuItem3[]= {" Item31... ",<BR>"
Item32... ",<BR>" Item add... ",<BR>" Item33 ", 0 };<BR>static char
* SubMenuItem4[]= {" Item41... ",<BR>" Item42... ",<BR>" Moving Text
",<BR>" Item44 ",<BR>" Item45 ",<BR>" item ** ", 0} ;<BR>static char
* SubMenuItem5[]= {" Help Index F1 ",<BR>" About... ",<BR>" System
Info ",0};<BR><BR>static char * SubMenuItem6[]= {0};<BR><BR>void
getitemcount(char ** ,int * ,int * ,int * );<BR><BR>void
LoadMainMenu(void);<BR><BR>void LoadSubMenu(char **name, int
ord);<BR><BR>int ManageSubMenu (void ) ;<BR><BR>void ManageMainMenu
(void) ;<BR>void DisplayMainMenu (void ) ;<BR>int DisplaySubMenu
(int ord) ;<BR>void Help_page_show(void) {return ; } ;<BR>void
Exitmenu (int) ;<BR>void In_ActiveMainMenuItem(int select , char
In_Active) ;<BR>void In_ActiveSubMenuItem(int ord , int select ,
char In_Active) ;<BR>int GetKey (void) ;<BR>void FuncProc (int ID)
;<BR>void Draw(void) ;<BR>void MoveText (void) ;<BR>void About
(void) ;<BR>void MessageBox(char * Message) ;<BR>void GoodBye(char *
pcInf1 , char * pcInf2) ;<BR><BR>void win();<BR>char
gettextattrib();<BR>void settextattrib();<BR>void
cprintfxy();<BR><BR>char *textbuf;<BR>MENUTYPE MainMenu ,
SubMenu[INUM] ;<BR>/* int maxx, texth, textw; */<BR><BR>void
main(void)<BR>{<BR><BR>clrscr();<BR>win(0,1,SCREENMAXX+1,SCREENMAXY,'\xb0',BLUE<<4|LIGHTSHOW(GREEN));<BR>cprintfxy(25,9,"Analytic
Hierarchy
Process",BLUE<<4|BLACK);<BR><BR>cprintfxy(26,11,"Howard.Hsu
&
WeiGuoZhang",BLUE<<4|BLACK);<BR>cprintfxy(33,18,"05/18/2000",BLUE<<4|BLACK);<BR>win(0,24,80,1,'
',WHITE<<4|BLUE);<BR>LoadMainMenu();<BR>LoadSubMenu
(SubMenuItem1 , 0);<BR>LoadSubMenu (SubMenuItem2 ,
1);<BR>LoadSubMenu (SubMenuItem3 , 2);<BR>LoadSubMenu (SubMenuItem4
, 3);<BR>LoadSubMenu (SubMenuItem5 , 4);<BR>LoadSubMenu
(SubMenuItem6 , 5);<BR>ManageMainMenu();<BR>}<BR><BR><BR>void
prncharxy(char xpos,char ypos,char ch,char attrib)<BR>{<BR>char far
*p=(char far *)0xb8000000;<BR>if(xpos<SCREENMINX ||
xpos>SCREENMAXX ||<BR>ypos<SCREENMINY ||
ypos>SCREENMAXY)<BR>return;<BR><BR>*(p+ypos%25*160+2*(xpos%80))=ch;<BR>*(p+ypos%25*160+2*(xpos%80)+1)=attrib;<BR>return;<BR>}<BR><BR><BR>void
cprintfxy(char xpos,char ypos,char *string,char attrib)<BR>{<BR>int
len,i;<BR>if(xpos<SCREENMINX || xpos>SCREENMAXX
||<BR>ypos<SCREENMINY ||
ypos>SCREENMAXY)<BR>return;<BR>len=strlen(string);<BR>for(i=0;i<len;i++)<BR>prncharxy(xpos+i,ypos,string[i],attrib);<BR>return;<BR>}<BR><BR>void
vcprintfxy(char xpos,char ypos,char string[],char
attrib)<BR>{<BR>int len,i;<BR>if(xpos<SCREENMINX ||
xpos>SCREENMAXX ||<BR>ypos<SCREENMINY ||
ypos>SCREENMAXY)<BR>return;<BR>len=strlen(string);<BR>for(i=0;i<len;i++)<BR>prncharxy(xpos,ypos+i,string[i],attrib);<BR>return;<BR>}<BR><BR>void
drawbox(char xpos,char ypos,char width,char heigh,<BR>char
*edge,char attrib,char *title){<BR><BR>char
i,j,len;<BR>if(xpos<SCREENMINX || xpos>SCREENMAXX
||<BR>ypos<SCREENMINY ||
ypos>SCREENMAXY)<BR>return;<BR><BR>prncharxy(xpos,ypos,edge[0],attrib);<BR>prncharxy(xpos+width-1,ypos,edge[2],attrib);<BR>prncharxy(xpos+width-1,ypos+heigh-1,edge[4],attrib);<BR>prncharxy(xpos,ypos+heigh-1,edge[5],attrib);<BR>for(i=0;i<width-2;i++){<BR>prncharxy(xpos+i+1,ypos,edge[1],attrib);<BR>prncharxy(xpos+i+1,ypos+heigh-1,edge[1],attrib);<BR>}<BR>for(i=0;i<heigh-2;i++){<BR>prncharxy(xpos,ypos+i+1,edge[3],attrib);<BR>prncharxy(xpos+width-1,ypos+i+1,edge[3],attrib);<BR>}<BR>len=strlen(title);<BR>cprintfxy(xpos+width/2-len/2,ypos,title,attrib);<BR><BR>for(i=0;i<heigh;i++)<BR>{<BR>settextattrib(xpos+width,ypos+i+1,(BLACK<<4)|(WHITE));<BR>settextattrib(xpos+width+1,ypos+i+1,(WHITE)|(WHITE));<BR><BR>}<BR>for(i=0;i<width-2;i++)<BR>settextattrib(xpos+2+i,ypos+heigh,(BLACK<<4)|(WHITE));<BR><BR><BR>for(i=1;i<heigh-1;i++)<BR>for(j=1;j<width-1;j++)<BR>prncharxy(xpos+j,ypos+i,'
',attrib);<BR><BR>return;<BR>}<BR><BR>void win(char xpos,char
ypos,char width,char heigh,char ch,char attrib)<BR>{<BR>char
i,j;<BR>if(xpos<SCREENMINX || xpos>SCREENMAXX
||<BR>ypos<SCREENMINY ||
ypos>SCREENMAXY)<BR>return;<BR>for(i=0;i<heigh;i++)<BR>for(j=0;j<width;j++)<BR>prncharxy(xpos+j,ypos+i,ch,attrib);<BR>return;<BR>}<BR><BR>char
*malloctextbuf(char width,char heigh)<BR>{<BR>char
*buf;<BR>if((buf=(char
*)malloc(2*width*heigh*sizeof(char)))==NULL)<BR>return
NULL;<BR>else<BR>return buf;<BR>}<BR><BR><BR>void gettextxy(char
xpos,char ypos,char width,char heigh,char *buf)<BR>{<BR>char
i,j;<BR>char far *vp=(char far
*)0xb8000000;<BR><BR>if(xpos<SCREENMINX || xpos>SCREENMAXX
||<BR>ypos<SCREENMINY ||
ypos>SCREENMAXY)<BR>return;<BR><BR>if(xpos+width>SCREENMAXX)<BR>width=SCREENMAXX+1-xpos;<BR>if(xpos+heigh>SCREENMAXY)<BR>heigh=SCREENMAXY+1-ypos;<BR><BR>for(i=0;i<heigh;i++)<BR>for(j=0;j<2*width;j++)<BR>buf[i*2*width+j]=*(vp+(ypos+i)%25*160+2*(xpos%80)+j);<BR>return;<BR>}<BR><BR>char
gettextattrib(char xpos,char ypos){<BR>char far *p=(char far
*)0xb8000000;<BR>if(xpos<SCREENMINX || xpos>SCREENMAXX
||<BR>ypos<SCREENMINY ||
ypos>SCREENMAXY)<BR>return;<BR>return(*(p+ypos%25*160+2*(xpos%80)+1));<BR>}<BR><BR>void
settextattrib(char xpos,char ypos,char attrib){<BR>char far *p=(char
far *)0xb8000000;<BR>if(xpos<SCREENMINX || xpos>SCREENMAXX
||<BR>ypos<SCREENMINY ||
ypos>SCREENMAXY)<BR>return;<BR>*(p+ypos*160+2*xpos+1)=attrib;<BR>return;<BR><BR>}<BR><BR>void
puttextxy(char xpos,char ypos,char width,char heigh,char
*buf)<BR>{<BR>char i,j,w,h;<BR>char far *vp=(char far
*)0xb8000000;<BR>if(xpos<SCREENMINX || xpos>SCREENMAXX
||<BR>ypos<SCREENMINY ||
ypos>SCREENMAXY)<BR>return;<BR>if(xpos+width>SCREENMAXX)<BR>w=SCREENMAXX+1-xpos;<BR>else<BR>w=width;<BR>if(ypos+heigh>SCREENMAXY)<BR>h=SCREENMAXY+1-ypos;<BR>else<BR>h=heigh;<BR><BR>for(i=0;i<h;i++)<BR>for(j=0;j<2*w;j++)<BR>*(vp+(ypos+i)%25*160+2*(xpos%80)+j)=buf[i*2*width+j];<BR>return;<BR>}<BR><BR><BR>void
ManageMainMenu (void )<BR>{<BR>unsigned key;<BR>int
ID;<BR>DisplayMainMenu();<BR>for(key=0;;)<BR>{<BR>key=GetKey()
;<BR>switch(key)<BR>{<BR>case LEFT
:<BR>In_ActiveMainMenuItem(MainMenu.select ,0)
;<BR>if(MainMenu.select<1) /* w Already leftest item in mainmenu
# */<BR>MainMenu.select =MainMenu.itemnum - 1
;<BR>else<BR>MainMenu.select--;<BR>In_ActiveMainMenuItem(MainMenu.select
, 1 ) ; /* R Light bar N */<BR>break ;<BR><BR>case RIGHT
:<BR>In_ActiveMainMenuItem(MainMenu.select ,
0);<BR>if(MainMenu.select>MainMenu.itemnum-2)<BR>MainMenu.select=0;<BR>else<BR>MainMenu.select++;<BR>In_ActiveMainMenuItem(MainMenu.select,1);<BR><BR>break;<BR><BR>case
DOWN:<BR>case
RETURN:<BR><BR>switch(MainMenu.COMMAND_ID[MainMenu.select]
){<BR>case 5: /*# Exit to DOS # */<BR>if (key==DOWN)<BR>break
;<BR>GoodBye ("Goodbye from ", "the MENU DEMO in graphics
mode.");<BR>break ;<BR>default :<BR><BR>ID = ManageSubMenu ();<BR>if
(ID >=0)<BR>FuncProc (ID);<BR>break
;<BR>}<BR>}<BR>}<BR>}<BR><BR>void FuncProc (int ID)<BR>{<BR>char
*buf;<BR>switch ( ID ){<BR>case 6: /*w 006 FileIQuit #
*/<BR><BR>GoodBye("Goodbye from ", "the BvIENU DEMO in graphics
mode. ") ;<BR>break ;<BR>case 101:<BR>Draw() ;<BR>break ;<BR>case
302:<BR>MoveText();<BR>break ;<BR>case 401:<BR>About ( ) ;<BR>break
;<BR>default
:<BR>buf=malloctextbuf(30+2,8+1);<BR>gettextxy(25,10,30+2,8+1,buf);<BR>drawbox(25,10,30,8,edge,RED<<4|GREEN,"
MessgeBox
");<BR>getch();<BR>puttextxy(25,10,30+2,8+1,buf);<BR>free(buf);<BR>break
;<BR>}<BR>}<BR><BR><BR>/* ManageSubMenu() retarn an int value that
is s /<BR>/# Il there is a error # /<BR>/# Return to main menu,
nothing to do # /<BR>/ =O or =>O; the COMMAND_ID of a menu item w
*/<BR><BR>int ManageSubMenu (void)<BR>{<BR><BR>MENUTYPE * mn =
&SubMenu[MainMenu.select] ;<BR>unsigned key
;<BR>if(DisplaySubMenu(MainMenu.select)) /* w Out of memory *
*/<BR>return -2;<BR>for(key=0;;)<BR>{<BR>key=GetKey () ;<BR>switch
(key ){<BR>case ESC: /* # return to MainMenu #
*/<BR>Exitmenu(MainMenu.select);<BR>return -1 ;<BR><BR>case
UP:<BR>In_ActiveSubMenuItem(MainMenu.select ,
mn->select,0);<BR>if(mn->select>0)<BR>mn->select--;<BR>else<BR>mn->select
= mn->itemnum - 1 ;<BR>In_ActiveSubMenuItem(MainMenu.select ,
mn->select ,1 );<BR>break ;<BR>case DOWN:<BR>In_ActiveSubMenuItem
(MainMenu. select , mn ->select , 0);<BR>if (mn ->select<mn
->itemnum - 1
)<BR>mn->select++;<BR>else<BR>mn->select=0;<BR>In_ActiveSubMenuItem
(MainMenu.select , mn->select ,1);<BR>break ;<BR>case
LEFT:<BR>Exitmenu (MainMenu.select);<BR>In_ActiveMainMenuItem
(MainMenu.select , 0);<BR>if(MainMenu.select<1) /* e Already
leftest item in mainmenu w */<BR>MainMenu.select = MainMenu.itemnum-
1 ;<BR>else<BR>MainMenu.select--
;<BR>In_ActiveMainMenuItem(MainMenu.select , 1) ; /* # Light bar e
*/<BR>if(DisplaySubMenu(MainMenu.select) )/* Out of mentory w
*/<BR><BR>return -2;<BR>mn= &SubMenu[MainMenu.select]
;<BR><BR>break ;<BR>case RIGHT :<BR>Exitmenu (MainMenu.select )
;<BR>In_ActiveMainMenuItem(MainMenu.select ,
0);<BR>if(MainMenu.select>MainMenu.itemnum-2)/* # already
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -