[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
(no subject)
From: |
Arvind V |
Subject: |
(no subject) |
Date: |
Wed, 12 Dec 2001 22:05:08 +0530 |
i am new to ncurses; i have been trying the menu library, and i can't seem
to get it working; can anybody find out what is wrong with the following
code?
I link with g++ -lmenu -lncurses filename.cpp
Here's the code...
=======================================================================
#include <menu.h>
#include <unistd.h>
#include <stdlib.h>
WINDOW *filemenu, *fmtitle;
MENU* myMenu;
/* itemList is an array of pointers to ITEMs
itemNames is an array of item names */
ITEM *itemList[6];
char *itemNames[5] = { "New", "Open", "Save", "Save As", "Exit" };
int i; //use for anything... ;-)
/*clean-up code*/
void cleanup()
{
echo(); nocbreak(); nl(); endwin();
}
/*ncurses initialization code*/
void initialize()
{
use_env(TRUE); initscr(); cbreak(); noecho(); nonl();
}
/*start colors, init color pairs etc */
void initColors()
{
if(has_colors())
{
start_color();
init_pair(1,COLOR_WHITE,COLOR_BLUE);
init_pair(2,COLOR_BLACK,COLOR_WHITE);
init_pair(3,COLOR_BLUE,COLOR_WHITE);
wbkgdset(filemenu,COLOR_PAIR(2)|WA_BOLD);
wbkgdset(fmtitle,COLOR_PAIR(3)|WA_BOLD);
}
}
void main()
{
/*init ncurses*/
initialize();
/*NULL terminated ITEMS** pointer list*/
itemList[5] = NULL;
/*dummy description string*/
char item[] = "MenuItem";
/*create menu items*/
for(i=0;i<5;i++)
{
itemList[i] = new_item(itemNames[i],item);
/*check for errors*/
if(!itemList[i])
{ cleanup(); printf("%s",itemNames[i]); exit(-1); }
}
/*make menu from itemList, check for errors*/
myMenu = new_menu(itemList);
if(!myMenu||item_count(myMenu)!=5)
{
cleanup(); printf("Menu allocation error. Exiting.\n");
exit(-1);
}
/*find size of window reqd for menu*/
int fmrows, fmcols;
scale_menu(myMenu,&fmrows, &fmcols);
/*create filemenu window accordingly...*/
filemenu = newwin(fmrows,fmcols,1,2);
fmtitle = newwin(1,10,0,2);
if(!(filemenu&&fmtitle))
{
cleanup();
printf("Not enough memory to allocate windows. Exiting.\n");
exit(-1);
}
keypad(filemenu,TRUE);
/*start_color, init color pairs, etc*/
initColors();
/* the next line is to force a window display*/
//wclear(filemenu); wrefresh(filemenu);
/* any of the next two lines make the menu go kaput
however it displays if i don't change the associated submenu
window from the default (stdscr).
What's going on? How can i get this to work?
*/
//set_menu_win(myMenu,fmtitle);
//set_menu_sub(myMenu,filemenu);
/*Curiously, though, the menu attributes set nicely.... */
set_menu_fore(myMenu,0x0100);
set_menu_back(myMenu,0x0200);
i = post_menu(myMenu);
/*the next line intends to force an update of the filemenu window*/
//wrefresh(filemenu); wgetch(filemenu);
getch(); cleanup();
}
=====================================================================
Thanx in advance...
Arvind
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
- (no subject), Arvind V, 2001/12/08
- (no subject),
Arvind V <=