C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-17-2002, 09:09 PM   #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
xlordt is offline   Reply With Quote
Old 04-18-2002, 05:36 AM   #2
B26354
 
Deckard's Avatar
 
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
Also, if you are having trouble linking, be sure to add the '-lcurses' switch to gcc.
__________________
Jason Deckard
Deckard is offline   Reply With Quote
Old 04-18-2002, 10:39 AM   #3
Registered User
 
Join Date: Dec 2001
Posts: 227
thanx i was wondering why it wasnt working for me.. hehe
xlordt is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 09:57 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22