-
box
well i have been working on this for a bit now but i cant seem to see why its not printing out the box with choices.. can anyone help
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);
}
i hope i can figure this out cause im a newbie and i think i will do better if i knew what am i doing wrong here ... thanx
-
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
Also, if you are having trouble linking, be sure to add the '-lcurses' switch to gcc.
-
thanx i was wondering why it wasnt working for me.. hehe