![]() |
| | #1 |
| Registered User Join Date: Dec 2001
Posts: 227
| box Code: int startx = 0;
int starty =0;
char *choices[] = { "choice 1",
"choice 2",
"choice 3",
"choice 4",
"Exit",
};
int n_choices = sizeof(choices) / sizeof(char *);
void print_menu(WINDOW *menu_win, int highlight);
int main()
{
WINDOW *menu_win;
int highlight = 1;
int choice = 0;
int c;
initscr();
clear();
cbreak();
noecho();
startx = ( 80 - WIDTH) / 2;
starty = ( 24 - HEIGHT) / 2;
menu_win = newwin(HEIGHT, WIDTH, startx, starty);
keypad(menu_win, TRUE);
mvprintw(0,0 ," Please select your choice");
refresh();
print_menu(menu_win, highlight);
while (1)
{
c = wgetch(menu_win);
switch (c)
{
case KEY_UP:
if( highlight == 1)
highlight = n_choices;
else
--highlight;
break;
case KEY_DOWN:
if( highlight == n_choices )
highlight = 1;
else
++highlight;
break;
case 10:
choice = highlight;
break;
default:
mvprintw(24,0, "You have pressed = %3d hope fully we can get %c",c, c);
refresh();
break;
}
print_menu(menu_win, highlight);
if (choice != 0)
break;
}
mvprintw(23, 0, "you have choces %d with %c\n",choice, choices[choice - 1] );
clrtoeol();
refresh();
endwin();
return 0;
}
void print_menu(WINDOW *menu_win, int highlight)
{
int x, y, i;
x = 2;
y = 2;
box(menu_win, 0, 0);
for (i=0; i<n_choices; ++i)
{
if (highlight == i+1)
{
wattron(menu_win, A_REVERSE);
mvwprintw(menu_win, y,x,"%s",choices[i]);
wattroff(menu_win, A_REVERSE);
}
else
mvwprintw(menu_win, y, x, "%s", choices[i]);
++y;
}
wrefresh(menu_win);
}
|
| xlordt is offline | |
| | #2 |
| B26354 Join Date: Jan 2002
Posts: 631
| I had to make a few additions to get it to compile, but the menu displayed fine for me. I added: Code: #include <curses.h> #define WIDTH 80 #define HEIGTH 24
__________________ Jason Deckard |
| Deckard is offline | |
| | #3 |
| Registered User Join Date: Dec 2001
Posts: 227
| thanx i was wondering why it wasnt working for me.. hehe |
| xlordt is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Virtual Box | ssharish2005 | Tech Board | 3 | 02-12-2009 05:08 AM |
| [MSVC] Is it valid to link against an import .lib generated from an executable? | pheres | C++ Programming | 9 | 02-13-2008 02:59 PM |
| How to program a "back" button with MFC | 99atlantic | Windows Programming | 3 | 04-26-2005 08:34 PM |
| New Theme | XSquared | A Brief History of Cprogramming.com | 160 | 04-01-2004 08:00 PM |
| Tab Controls - API | -KEN- | Windows Programming | 7 | 06-02-2002 09:44 AM |