Thread: box

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    227

    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

  2. #2
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    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.
    Jason Deckard

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    thanx i was wondering why it wasnt working for me.. hehe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Virtual Box
    By ssharish2005 in forum Tech Board
    Replies: 3
    Last Post: 02-12-2009, 05:08 AM
  2. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  3. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM