Very like interface written with Turbo Vision.
/ * Date: 05/2000 Topic: Text Menu Pass By: TurboC 20
* /
# include
# Define ScreenMinx 0 # define screenminy 0 # define screenmaxx 79 # define screenmaxy 24
#define windowmaxx 79 # Define windowminx 0 # define windowmaxy 24 # define windowminy 0
/ * #define blink 0x80 * / # define light 0x08 # define white 0x07 # define black 0x00 # define red 0x04 # define green 0x02 # define blue 0x01
#define mixcolor (a, b) a | b # define lightshow (a) a | light # define darkshow (a) a & 0xf7 # define blinkshow (a) a | blink # define notblinkshow (a) a & 0x7f # define backcolor (a) a << 4 # define Mix (A, B) (A | BackColor (b)) # define getBackColor (A) ((A & 0x70) >> 4) #define getforecolor (a) a & 0x0f # define enabledselectMenuItem Mix (Black, White) # Define EnabledMenuItem Mix (Black, Green) #define DisabledSelectMenuItem Mix (Lighshow (Black), Black #define DisabledMenuItem Mix (LIGHSHOW (Black), White)
# Define INSERT 0x5200 # define ESC 0x001b # define TAB 0x0f09 # define RETURN 0x000d # define RIGHT 0x4d00 # define LEFT 0x4b00 # define UP 0x4800 # define DOWN 0x5000 # define BS 0x0e08 # define HOME 0x4700 # define END 0x4f00 # define PGUP 0x4900 # define PGDN 0x5100 # define DEL 0x5300 # define F1 0x3b00 # define F2 0x3c00 # define F3 0x3d00 # define F4 0x3e00 # define F5 0x3f00 # define F6 0x4000 # define F7 0x4100 # define F8 0x4200 # define F9 0x4300 # define F10 0x4400
# Define MenuInGround 1 # define MenuActiveGround 2 # define MenuActiveItem 3 # define MenuInItem 4 # define MenuEdge 5 # define WindowEdge 6 # define WindowGround 7 # define PopWindow 8 / * unsigned char AllColors [20] = {0, CYAN, LIGHTRED, YELLOW, Black, White, Lightred, Blue, Cyan, 9, 10, 11, 12, 13, 14, 15}; * /
TypedEf unsigned char uchar; typef unsigned int uint; typef unsigned long;
Char Edge [7] = {0xDA, 0xC4, 0XBF, 0XB3, 0XD9, 0XC0, '/ 0'};
/ * CHAR EDGE1 [7] = {}; * /
#define Inum 10 / * R Maximum IO ITENLS in Each Menu W * /
Typedef struct _meu {char coor [4]; / * the menu's area w * / char itemcoor [4 * inum]; / * max ITEM, Each with xl, yl, x2, y2 w * / char oremdispxy [2 * inum ]; / * Actually w * / char select; / * selected item's ord # * / char oremnum; / * The number of items in this menu w * / char ** itemname; / * w item's name Point to static data) r * / int command_id [inum]; / * w Key Number r * /} menutype;
Static char * mainmenuitem [] = {"File", "Edit", "Run", "Compile", "Help", "EXIT", 0}; static char * syshelp = "F1-Help F5-Zoom F6-Switch F7-TRACE F8-STEP F9-MAKE F10-MENU ";
Static char * submenuitem1 [] = {"Load File ... F3", "Pick File Alt F3", "New", "Save F2", "Write to", "OS Shell", "Quit Alt X" , 0}; / * static char * SubMenuItem [6] [] = {{"Help11 ..."}, {* / static char * submenuitem2 [] = {"Item21 ...", "draw", "item23 "," Item 24 "," Item25 "," Item26 "," Item27 "," Item28 ", 0}; Static Char * SubMenuItem3 [] = {" Item31 ... "," Item32 ... "," Item Add ... "," item33 ", 0}; static char * submenuitem4 [] = {" Item41 ... "," item42 ... "," moving text "," item44 "," item45 "," item * * ", 0}; static char * submenuitem5 [] = {" Help Index F1 "," About ... "," System Info ", 0};
Static char * submenuitem6 [] = {0};
Void getItemcount (char **, int *, int *, int *);
Void loadingMainMenu (void);
Void LoadSubmenu (Char ** Name, Int ORD);
Int ManageSubmenu (Void);
void ManageMainMenu (void); void DisplayMainMenu (void); int DisplaySubMenu (int ord); void Help_page_show (void) {return;}; void Exitmenu (int); void In_ActiveMainMenuItem (int select, char In_Active); void In_ActiveSubMenuItem (int ord , int select, char in_active; int getKey (void); void draw (void); void movext (void); Void About (void); void messagebox; void goodbye Char * pcinf1, char * pcinf2); void win (); char gettextattrib (); void setTextAttrib (); void cprintfxy ();
Char * textbuf; menutype mainmenu, submenu [inum]; / * int Maxx, Texth, Textw; * /
Void main (void) {
CLRSCR (); WIN (0, 1, ScreenMaxX 1, Screenmaxy, '/ XB0', Blue << 4 | LightShow (Green); CPrintfxy (25, 9, "Analytic Hierarchy Process", Blue << 4 | Black );
CPrintFXY (26, 11, "Howard.hsu & weiguozhang", Blue << 4 | black; CPrintfxy (33, 18, "05/18/2000", Blue << 4 | black; WIN (0,24, 80,1, '', WHITE << 4 | BLUE); LoadMainMenu (); LoadSubMenu (SubMenuItem1, 0); LoadSubMenu (SubMenuItem2, 1); LoadSubMenu (SubMenuItem3, 2); LoadSubMenu (SubMenuItem4, 3); LoadSubMenu (SubMenuItem5 , 4); LoadSubmenu (Submenuitem6, 5); ManageMainMenu ();
Void Prncharxy (Char XPOS, Char Ypos, Char Ch, Char attrib) {Char Far * P = (Char Far *) 0xB8000000; IF (XPOS
* (p ypos% 25 * 160 2 * (XPOS% 80)) = CH; * (p ypos% 25 * 160 2 * (XPOS% 80) 1) = attrib; return;}
Void CPrintfxy (Char Xpos, Char Ypos, Char * String, Char attrib) {Int Len, i; IF (XPOS Void Drawbox (Char Xpos, Char Ypos, Char Width, Char Heigh, Char * Edge, Char Attrib, Char * Title) { CHAR I, J, LEN; IF (XPOS Prncharxy (XPOS, YPOS, EDGE [0], Attrib); Prncharxy (XPOS Width-1, Ypos, Edge [2], Attrib); Prncharxy (xpos width-1, ypos heigh-1, Edge [4] , attrib); Prncharxy (xpos, ypos heigh-1, edge [5], attrib); for (i = 0; i For (i = 0; i } for (i = 0; i For (i = 1; i Void Win (Char Xpos, Char Ypos, Char Width, Char Heigh, Char Ch, Char attrib) {Char I, J; IF (XPOS Char * malloctextbuf (char width, char heigh) {char * buf; IF ((buf = (char *) malloc (2 * width * heigh * sizeof (char)) == null) Return Null; else return; Void gettextxy (char xpos, char ypos, char width, char heigh, char * buf) {char i, j; char far * vp = (char far *) 0xB8000000; IF (XPOS IF (xpos width> screenmaxx) width = screenmaxx 1-xpos; if (xpos heigh> screenmaxy) heigh = screenmaxy 1-ypos; For (i = 0; i Char gettextattrib (char Xpos, char ypos) {char far * p = (char far far *) 0xB8000000; IF (XPOS Void setTextAtttrib (Char Xpos, Char Ypos, Char attrib) {char far * p = (char far *) 0xB8000000; IF (XPOS } Void Puttextxy (Char Xpos, Char Ypos, Char Width, Char Heigh, Char * BUF) {Char i, J, W, H; Char Far * VP = (Char Far *) 0xB8000000; IF (XPOS Void ManageMainMenu (void) {Unsigned Key; INT ID; DisplayMainMenu (); for (key = 0 ;;) {key = getKey (); switch (key) {copy left: in_ActiveMainMenuitem (mainmenu.select, 0); IF Mainmenu.select <1) / * W Already Leftest Item in mainmenu # * / mainmenu.select = mainmenu.itemnum - 1; else mainmenu.select--; in_ActivemainMenuItem (mainmenu.select, 1); / * r Light bar n * / Break; Case Right: in_ActiveMainMenuitem (mainmenu.select, 0); if (mainmenu.select> mainmenu.itemnum-2) mainmenu.select = 0; Else Mainmenu.select ; in_ActiveMainMenuItem (MainMenu.select, 1); Break; Case Down: Case Return: Switch (mainmenu.command_id [mainmenu.select]) {case 5: / * # EXIT to DOS # * / if (key == down) Break; Goodbye ("Goodbye from", "The Menu Demo in graphics mode.") Break; Default: ID = manageSubMenu (); if (id> = 0) FuncProc (ID); Break;}}}} Void FuncProc (int id) {char * buf; switch (id) {case 6: / * w 006 fileiquit # * / Goodbye ("Goodbye from", "The Bvienu Demo in Graphics Mode."); Break; Case 101: Draw (); Break; Case 302: MoveText (); Break; Case 401: About (); Break; Default: BUF = MallOCTextBuf (30 2, 8 1); GetTextxy (25, 10, 30 2, 8 1, BUF); DrawBox (25, 10, 30, 8, Edge, Red << 4 | Green, "MessGebox "); GetCH (); Puttextxy (25, 10, 30 2, 8 1, buf); free (buf); Break;}} / * manageSubmenu () retarn an int value this is s / / / # il there Is A Error # / / / / / / = => o; The Command_id of A Menu Item W * / INT ManageSubmenu (void) { MenuType * Mn = & SubMenu [mainmenu.select]; unsigned key; if (marinmenu.select) / * w out of memory * * / return -2; for (key = 0 ;;) {key = getKey () Switch (key) {copy esc: / * # Return to mainmenu # * / exitMenu (mainmenu.select); return -1; Case Up: in_ActiveSubMenuItem (MainMenu.select, mn-> select, 0); if (mn-> select> 0) mn-> select--; else mn-> select = mn-> itemnum - 1; in_ActiveSubMenuItem (Mainmenu. SELECT, MN-> SELECT, 1); Break; Case Down: In_ActiveSubmenuitem (Mainmenu, SELECT, MN -> SELECT, 0); IF (Mn -> Select break; case RIGHT: Exitmenu (MainMenu.select); In_ActiveMainMenuItem (MainMenu.select, 0); if (MainMenu.select> MainMenu.itemnum-2) / * # already rightest w * / MainMenu.select = 0; else MainMenu. select ; In_ActiveMainMenuItem (MainMenu.select, 1); if (DisplaySubMenu (MainMenu.select)) / * # Out of memory w * / return -2; mn = & SubMenu [MainMenu select.]; break; case rETURN: Exitmenu (MainMenu .select); Return Mn-> Command_id [mn-> select];}}} Void LoadmainMenu () {Int Count, Totallen, Maxlen, I; Int Beginx; MainMenu.coor [0] = ScreenMinx; MainMenu.coor [1] = ScreenMiny; mainmenu.coor [2] = ScreenMaxx; mainmenu.coor [3] = Screenminy; GetItemcount (MainMenuItem, & Count, & Totallen, & Maxlen); Mainmenu.itemnum = count; beginx = 3; for (i = 0; i Mainmenu.itemdispxy [i * 2] = beginx; / * w Actuall Disp x w * / mainmenu.itemdispxy [i * 2 1] = mainmenu.coor [3]; / * w Actuall Disp y w * / Mainmenu.command_id [i] = i; Beginx = Beginx Strlen (MainMenuItem [I]) 1;} mainmenu.itemname = mainmenuitem; Void LoadSubmenu (CHAR ** Name, Int ORD) {Int Count, I, J, Maxlen; GetItemcount (Name, & Count, & I, & Maxlen); Submenu [ORD] .ItemName = Name SubMenu [ORD] .itemnum = count; j = maxlen 1; if (j mainmenu.Itemcoor [4 * ord] IF (count == 0) {SubMenu [ORD] .coor [1] = SubMenu [ORD] .COOR [1] 1; / * w the item's y2 * / submenu [ord] .coor [3] = SubMenu [ ORD] .chouse [1];} else {submenu [ORD] .COOR [1] = mainmenu.Itemc ORD 3] 1; Submenu [ORD] .coor [3] = Submenu [ORD] .coor [1] count 1;} for (i = 0; i SubMenu [ORD] .ItemDispxy [i * 2] = SubMenu [ORD] .ItemCoor [i * 4]; SubMenu [ORD] .ItemDispxy [i * 2 1] = SubMenu [ORD] .Itemcoor [i * 4 1 ]; SubMenu [ORD] .command_id [i] = ORD * 100 I;}} Void DisplayMainMenu (void) {Unsigned i; win (mainmenu.coor [0], mainmenu.coor [1], 80, 1, '', white << 4 | black); for (i = 0; i Char * textbuf; INT DisplaySubmenu (int ORD) {Unsigned Size, I; MenuType * Mn = & SubMenu [ORD]; TextBuf = NULL; TextBuf = MallOCtextBuf (Mn-> Coor [2] -Mn-> Coor [0] 1 2, MN -> COOR [3] -Mn-> COOR [1] 1 1); if (TextBuf == Null) {CLRSCR (); Printf ("/ NOUT OF MEMORY!"); Printf ("/ NPRESS ANY Key ... "); getch (); return 1;}} (mn-> coor [1] == mn-> coor [3]) Return 0; getTextxy (mn-> coor [0], mn-> coor [1], Mn-> Coor [2] -Mn-> Coor [0] 1 2, Mn-> Coor [3] -Mn-> Coor [1] 1 1, TextBuf; DrawBox (MN -> Coor [0], MN-> Coor [1], Mn-> COOR [2] -MN-> Coor [0] 1, Mn-> COOR [3] -Mn-> Coor [1] 1 , Edge, White << 4 | Black, ""); For (i = 0; i } Static void exitmenu (int → menutype * mn = & submenu [ore); if (textbuf) {PUTTEXTXY (mn-> coor [0], mn -> coor [1], mn-> coor [2] -MN- > COOR [0] 1 2, Mn-> COOR [3] -Mn-> Coor [1] 1 1, TextBuf); Free (TextBuf);}} Void in_ActiveMainMenuItem (int search, char in_active) {menutype * tp = & mainmenu IF (in_Active == 0) / * h off w * / {cprintfxy (tp-> itemdispxy [select * 2], tp-> itemdispxy [select * 2 1], tp -> itemname [select], (White < <4) | black);} else {cprintfxy (tp-> itemdispxy [select * 2], tp-> itemdispxy [select * 2 1], tp -> itemname [select], (Green << 4) | Blue }}}}} Void in_ActiveSubMenuItem (int ORD, INT SELECT, CHAR IN_ACTIVE) {menutype * TP = & submenu [ORD]; if (in_Active == 0) / * w Off w * / {cprintfxy (tp-> itemdispxy [select * 2], TP -> ItemDispxy [SELECT * 2 1], TP -> ItemName [select], (White << 4) | black;} else {cprintfxy (tp-> itemdispxy [select * 2], TP- > itemdispxy [select * 2 1], tp -> itemname [select], (Green << 4) | blue);}} INT getKey (void) {int key; key = bioskey (0); if (key == f1) Help_page_show (); else if (key << 8) {key = key & 0x00ff; IF (isalpha) key = Toupper (key);} Return Key; Static void getItemcount (CHAR ** S, INT * Count, INT * LEN, INT * MAXLEN) {INT I, J; for (* Maxlen) = 0, (* LEN) = 0, i = 0; s [i ]! = NULL; i ) {j = strlen (s [i]); (* len) = j; if (j> (* maxlen)) (* maxlen) = j;} (* count) = i; } Void Draw (Void) {INT X, X1, X2, Y1, Y2; Randomize (); Do {x1 = Random (WindowMaxx-Windowminx) WINDOWMINX; Y1 = Random (WindowMaxy-WINDOWMINY) WINDOWMINY; X2 = Random (WindowMaxx -Windowminx) WINDOWMINX; Y2 = RandoM (WindowMaxy-Windowminy) WINDOWMINY; if (x1> x2) {x = x1; x1 = x2; x2 = x;} if (Y1> Y2) {x = Y1; Y1 = Y2; Y2 = x;} IF (Y1 <1) Y1 = 1; if (Y2> 23) Y2 = 23; WIN (X1, Y1, X2-Y1 1, Y2-Y1 1, '', Random 256); delay (100);} while (! Bioskey (1));} void about (void) {char MIDX, MIDY, X1, Y1, X2, Y2, Size; Char * BUF1; MIDX = (WindowMaxX - Windowminx) / 2; Midy = (WindowMaxy - Windowmin) / 2; x1 = midx-15; x2 = midx 15; y1 = midy-4; y2 = midy 4; buf1 = malloctextbuf (x2-x1 1 2 Y2-y1 1 1); GetTextxy (x1, y1, x2-x1 1 2, Y2-Y1 1 1, BUF1); / * WIN (WindowMAXX, Windowmaxy, '', Blue); * / if (buf1 == null) {clrs (); printf ("/ nout of memory! Press any key to exit ..."): "/ NOUT OF MEMORY! PRESS ANY KEY TO EXIT ...") GetCH (); exit (1);} else {gettextxy (x1, y1, x2-x1 1 2, y2-y1 1 1, buf1); DrawBox (x1, y1, x2-x1 1, Y2-Y1 1, Edge, White, "About ..."); CPrintFxy (MIDX-Strlen ("MENU DEMO") / 2, MIDY-2, "Menu Demo", Red); CPrintFxy (MIDX-Strlen "In text mode") / 2, MIDY-1, "in text mode", red); CPRINTFXY (MIDX-STRLEN ("05/2000 by") / 2, Midy, "05/2000 by", RED) CPrintfxy ("Howard.hsu") / 2, MIDY 1, "Howard.hsu", Red); CPrintFxy (MIDX-Strlen ("OK") / 2, Midy 2, "OK", GREEN ); GetCH (); puttextxy (x1, y1, x2-x1 1 2, y2-y1 1 1, buf1); free (buf1);}} void DrawButtonup (unsigned char xpos, unsigned char ypos, char ypos, char ypos * Message, Char attrib) {Unsigned Char Len, I; Char backattrib; backattrib = GetTextAttrib (xpos, ypos); len = strlen (Message); Prncharxy (xpos, ypos, '', attrib); CPRINTFXY (XPOS 1, YPOS, Message, Attrib Prncharxy (XPOS LEN 1, YPOS, '', Attrib); Prncharxy (XPOS LEN 2, YPOS, 240, Backattrib); for (i = 0; i <= len 2; i ) Prncharxy (XPOS I 1, YPOS 1, 220, Backattrib); Return;} void DrawButtonDown (unsigned char xpos, unsigned char ypos, char * message, char attrib) {unsigned char len, i; char BackAttrib; BackAttrib = gettextattrib (xpos, ypos 1); len = strlen (message); prncharxy (xpos, Ypos, '', backattrib; Prncharxy (XPOS 1, YPOS, '', Attrib); CPrintfxy (XPOS 2, YPOS, Message, Attrib); Prncharxy (XPOS LEN 2, YPOS, '', Attrib) For (i = 0; i <= len 2; i ) prncharxy (xpos, ypos 1, '', backattrib); return; void messagebox (char * mess) {int MIDX, MIDY, X1, Y1, X2, Y2, Size, Len; Char * BUF1; MIDX = (WindowMaxx - Windowmin) / 2; Midy = (WindowMaxy - Windowminy) / 2; Len = Strlen (Message)> Strlen ("MessageBox")? Strlen (Message) : Strlen ("MessageBox"); x1 = midx-le; x2 = midx len; y1 = midy-4; y2 = midy 4; buf1 = malloctextbuf (x2-x1 1 2, y2-y1 1 1); if (buf1 == null) {CLRSCR (); Printf ("/ NOUT OF MEMORY! PRESS ANY Key to Continue ..."); getCh (); exit (1);} else {gettextxy (x1, Y1, X2-X1 1 2, Y2-Y1 1 1, BUF1); DRAWB OX (x1, y1, x2-x1 1, y2-y1 1, ed, green << 4 | red, "messagebox"); CPrintFxy (MIDX-Strlen (Message) / 2, MIDY-1, Message, Green << 4 | Blue); DrawButtonUp (MIDX-Strlen ("OK") / 2-2, Midy 2, "OK", Red); Getch (); DrawButtondown (MIDX-Strlen ("OK") / 2-2, MIDY 2, " OK ", Red); DELAY (5000); Puttextxy (x1, y1, x2-x1 1 2, y2-y1 1 1, buf1); free (buf1);}} Void MoveText (void) {INT i; char attrib; WIN (0, 1, 80, 23, ', 0); for (i = random (80); i> 1; I- = 2) { Attrib = GetTextAtttrib (i, 14); CPrintFxy (i, 14, "menu example!" ((Blue << 4) & 0x80) | red); delay (2000); CPrintfxy (i, 14, ", attrib) ; } Void Goodbye (Char * PCINF1, Char * PCINF2) {INT F; CLRSCR (); WINDOW (1, 1, 80, 1); TextBackground (LightBlue); CLRSCR (); highvideo (); TextColor (White); CPRINTF PCINF1); TextColor (YELLOW); CPRINTF (PCINF2); Window (1, 1, 80, 25); Printf ("/ n"); for (f = 400; f <800; f = 100) {Sound (f ); DELAY (100);} nosound (); exit (0);