⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tc20写的dos底下文本菜单.htm

📁 一些c的经典案例
💻 HTM
📖 第 1 页 / 共 3 页
字号:
            <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 &lt;graphics.h&gt;<BR># include 
            &lt;alloc.h&gt;<BR># include &lt;process.h&gt;<BR># include 
            &lt;stdio.h&gt;<BR># include &lt;stdlib.h&gt;<BR># include 
            &lt;time.h&gt;<BR># include &lt;string.h&gt;<BR># include 
            &lt;dos.h&gt;<BR># include &lt;bios.h&gt;<BR># include 
            &lt;conio.h&gt;<BR># include &lt;ctype.h&gt;<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&amp;0xf7<BR>#define BLINKSHOW(A) A|BLINK<BR>#define 
            NOTBLINKSHOW(A) A&amp;0x7f<BR>#define BACKCOLOR(A) 
            A&lt;&lt;4<BR>#define MIX(A,B) (A | BACKCOLOR(B))<BR>#define 
            GetBackColor(A) ((A&amp;0x70)&gt;&gt;4)<BR>#define GetForeColor(A) 
            A&amp;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&lt;&lt;4|LIGHTSHOW(GREEN));<BR>cprintfxy(25,9,"Analytic 
            Hierarchy 
            Process",BLUE&lt;&lt;4|BLACK);<BR><BR>cprintfxy(26,11,"Howard.Hsu 
            &amp; 
            WeiGuoZhang",BLUE&lt;&lt;4|BLACK);<BR>cprintfxy(33,18,"05/18/2000",BLUE&lt;&lt;4|BLACK);<BR>win(0,24,80,1,' 
            ',WHITE&lt;&lt;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&lt;SCREENMINX || 
            xpos&gt;SCREENMAXX ||<BR>ypos&lt;SCREENMINY || 
            ypos&gt;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&lt;SCREENMINX || xpos&gt;SCREENMAXX 
            ||<BR>ypos&lt;SCREENMINY || 
            ypos&gt;SCREENMAXY)<BR>return;<BR>len=strlen(string);<BR>for(i=0;i&lt;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&lt;SCREENMINX || 
            xpos&gt;SCREENMAXX ||<BR>ypos&lt;SCREENMINY || 
            ypos&gt;SCREENMAXY)<BR>return;<BR>len=strlen(string);<BR>for(i=0;i&lt;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&lt;SCREENMINX || xpos&gt;SCREENMAXX 
            ||<BR>ypos&lt;SCREENMINY || 
            ypos&gt;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&lt;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&lt;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&lt;heigh;i++)<BR>{<BR>settextattrib(xpos+width,ypos+i+1,(BLACK&lt;&lt;4)|(WHITE));<BR>settextattrib(xpos+width+1,ypos+i+1,(WHITE)|(WHITE));<BR><BR>}<BR>for(i=0;i&lt;width-2;i++)<BR>settextattrib(xpos+2+i,ypos+heigh,(BLACK&lt;&lt;4)|(WHITE));<BR><BR><BR>for(i=1;i&lt;heigh-1;i++)<BR>for(j=1;j&lt;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&lt;SCREENMINX || xpos&gt;SCREENMAXX 
            ||<BR>ypos&lt;SCREENMINY || 
            ypos&gt;SCREENMAXY)<BR>return;<BR>for(i=0;i&lt;heigh;i++)<BR>for(j=0;j&lt;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&lt;SCREENMINX || xpos&gt;SCREENMAXX 
            ||<BR>ypos&lt;SCREENMINY || 
            ypos&gt;SCREENMAXY)<BR>return;<BR><BR>if(xpos+width&gt;SCREENMAXX)<BR>width=SCREENMAXX+1-xpos;<BR>if(xpos+heigh&gt;SCREENMAXY)<BR>heigh=SCREENMAXY+1-ypos;<BR><BR>for(i=0;i&lt;heigh;i++)<BR>for(j=0;j&lt;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&lt;SCREENMINX || xpos&gt;SCREENMAXX 
            ||<BR>ypos&lt;SCREENMINY || 
            ypos&gt;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&lt;SCREENMINX || xpos&gt;SCREENMAXX 
            ||<BR>ypos&lt;SCREENMINY || 
            ypos&gt;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&lt;SCREENMINX || xpos&gt;SCREENMAXX 
            ||<BR>ypos&lt;SCREENMINY || 
            ypos&gt;SCREENMAXY)<BR>return;<BR>if(xpos+width&gt;SCREENMAXX)<BR>w=SCREENMAXX+1-xpos;<BR>else<BR>w=width;<BR>if(ypos+heigh&gt;SCREENMAXY)<BR>h=SCREENMAXY+1-ypos;<BR>else<BR>h=heigh;<BR><BR>for(i=0;i&lt;h;i++)<BR>for(j=0;j&lt;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&lt;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&gt;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 &gt;=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&lt;&lt;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 =&gt;O; the COMMAND_ID of a menu item w 
            */<BR><BR>int ManageSubMenu (void)<BR>{<BR><BR>MENUTYPE * mn = 
            &amp;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-&gt;select,0);<BR>if(mn-&gt;select&gt;0)<BR>mn-&gt;select--;<BR>else<BR>mn-&gt;select 
            = mn-&gt;itemnum - 1 ;<BR>In_ActiveSubMenuItem(MainMenu.select , 
            mn-&gt;select ,1 );<BR>break ;<BR>case DOWN:<BR>In_ActiveSubMenuItem 
            (MainMenu. select , mn -&gt;select , 0);<BR>if (mn -&gt;select&lt;mn 
            -&gt;itemnum - 1 
            )<BR>mn-&gt;select++;<BR>else<BR>mn-&gt;select=0;<BR>In_ActiveSubMenuItem 
            (MainMenu.select , mn-&gt;select ,1);<BR>break ;<BR>case 
            LEFT:<BR>Exitmenu (MainMenu.select);<BR>In_ActiveMainMenuItem 
            (MainMenu.select , 0);<BR>if(MainMenu.select&lt;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= &amp;SubMenu[MainMenu.select] 
            ;<BR><BR>break ;<BR>case RIGHT :<BR>Exitmenu (MainMenu.select ) 
            ;<BR>In_ActiveMainMenuItem(MainMenu.select , 
            0);<BR>if(MainMenu.select&gt;MainMenu.itemnum-2)/* # already 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -