Subj : Re: menu item choice question...? To : borland.public.cpp.borlandcpp From : mujeebrm Date : Sat Sep 17 2005 11:37 am thanx Wayne, mujeebrm "Wayne A. King" wrote in message news:432af97e.20413864@newsgroups.borland.com... > On Thu, 15 Sep 2005 21:55:29 +0500, mujeebrm > wrote: > >>/* menu.c, bc 5.02/tc 3, winxp */ >>/* plz help me in this logic, how can i modify this my program >> of a simple menu so that when i press down arrow key it >> makes previous items bgcolor black and fgcolor white and >> selected items bgcolor red and fgcolor white and vice versa >> and when i press enter it should call respective function >> this should keep going on untill i press enter on exit menu item...? > [snip] > > At this time, I have neither time nor inclination to analyze or modify > your > example. See if this old example from my archives gives you some > ideas as to how to approach the problem: > > /****************** LIGHTBAR.C ********************/ > /** Based on Public Domain code by Roger Scudder **/ > /** originally posted in the FIDO C_Echo - 01/96 **/ > /** Compiled with Borland Turbo C++ v3.0 for DOS **/ > /** -------------------------------------------- **/ > /** Modifications made by Wayne A. King 03/96 **/ > /** (1) Added HOME, END, PAGE_UP, and PAGE_DOWN **/ > /** processing. **/ > /** (2) Added roll-over of bar positioning when **/ > /** at first or last item. **/ > /** (3) Added menu item selection by number. **/ > /** (4) Added cursor on/off code. **/ > /** (5) Added display of menu selection at end. **/ > /**************************************************/ > #include > #include > > /* key values */ > #define UP 72 > #define DOWN 80 > #define ESC 27 > #define ENTER 13 > #define HOME 71 > #define END 79 > #define PAGE_UP 73 > #define PAGE_DOWN 81 > > /* limits */ > #define NUM_ITEMS 4 > #define FIRST_ROW 5 > > /* define an array of pointers to the menuitems */ > char *item[NUM_ITEMS] = { "[1] Word Perfect 5.1 ", > "[2] Lotus 123 ", > "[3] Turbo C++ 3.0 ", > "[4] Qedit " }; > > void showlight(char *s, int col, int row) /* show menuitem highlighted */ > { > textcolor(BLACK); > textbackground(WHITE); > gotoxy(col, row); > cputs(s); > textcolor(LIGHTCYAN); > textbackground(BLACK); > gotoxy(col, row); > } > > int menu(void) /* return: number of menuitem or -1 if Esc is pressed */ > { > int col = 30, row = FIRST_ROW, key, ext, i; > > clrscr(); > textcolor(WHITE); > textbackground(BLACK); > gotoxy(col, row-2); > > cputs(" >>>> PROGRAMS <<<<"); > > textcolor(LIGHTCYAN); > for(i = NUM_ITEMS - 1; i > 0; i--) > { > gotoxy(col, row + i); > cputs(item[i]); > } > showlight(item[i] , col, row); > > /* handle user key strokes */ > for(;;) > { > ext = 0; > if((key = getch()) == 0) > ext = getch(); > > switch(ext) > { > case PAGE_UP: > case HOME: cputs(item[row - FIRST_ROW]); > row = FIRST_ROW; > break; > case PAGE_DOWN: > case END: cputs(item[row - FIRST_ROW]); > row = FIRST_ROW + NUM_ITEMS - 1; > break; > case UP: cputs(item[row - FIRST_ROW]); > if(row == FIRST_ROW) > { > row += NUM_ITEMS-1; > break; > } > if(row > FIRST_ROW) > row--; > break; > case DOWN: cputs(item[row - FIRST_ROW]); > if(row == FIRST_ROW + NUM_ITEMS - 1) > { > row -= NUM_ITEMS-1; > break; > } > if(row < FIRST_ROW + NUM_ITEMS - 1) > row++; > break; > } > if(key == ENTER) return row - FIRST_ROW; > if(key == ESC) return -1; > key -= 0x30; > if(key > 0 && key <= NUM_ITEMS) /* menu item number */ > { > cputs(item[row - FIRST_ROW]); > row = FIRST_ROW+key-1; > showlight(item[key-1], col, row); > return key-1; > } > showlight(item[row - FIRST_ROW], col, row); > } > } > > int main(void) > { > int itemno; > > _setcursortype(_NOCURSOR); > itemno = menu(); > gotoxy(1, 24); > if(itemno == -1) cprintf("Escape key pressed!"); > else cprintf("You selected menu item %s", item[itemno]); > _setcursortype(_NORMALCURSOR); > return EXIT_SUCCESS; > } > > -- > Wayne A. King > (waking@idirect.com, Wayne_A_King@compuserve.com) .