我正在使用NCurses尝试获得所需的输出:
但是使用以下代码:
int main(void)
{
WINDOW *white_space,*red_space,*blue_box;
int maxx,maxy;
initscr();
start_color();
init_pair(1,COLOR_WHITE,COLOR_BLUE);
init_pair(2,COLOR_RED,COLOR_WHITE);
init_pair(3,COLOR_BLACK,COLOR_GREEN);
init_pair(4,COLOR_RED,COLOR_RED);
white_space = subwin(stdscr,10,76,6,2);
red_space = subwin(stdscr,1,80,23,0);
getmaxyx(white_space,maxy,maxx);
blue_box = subwin(white_space,maxy-1,maxx-1,8,20);
if(white_space == NULL)
{
addstr("Unable to create subwindow\n");
endwin();
return 1;
}
bkgd(COLOR_PAIR(1));
addstr("Master window");
wbkgd(white_space,COLOR_PAIR(2));
mvwprintw(white_space, 0, 0, "%46s", "White space");
wbkgd(blue_box,COLOR_PAIR(4));
wbkgd(red_space,COLOR_PAIR(3));
waddstr(red_space,"Alert area");
wrefresh(white_space);
wrefresh(stdscr);
refresh();
getch();
endwin();
return 0;
}
我得到以下输出:
是否可以在子窗口中创建子窗口?
由于
答案 0 :(得分:0)
ncurses(任何非错误版本的curses)都支持子窗口,如manual中所述。
在给定的示例中,注意到一些问题:
white_space = subwin(stdscr,10,76,6,2);
red_space = subwin(stdscr,1,80,23,0);
getmaxyx(white_space,maxy,maxx);
blue_box = subwin(white_space,maxy-1,maxx-1,8,20);
例如:
white_space
的初始尺寸没有考虑实际的屏幕尺寸(可能比80列窄)blue_box
所要求的尺寸仅略小于white_space
,但距离窗口不能(80列)显示的距离足够远。如果是这样,则不会创建任何窗口。 ncurses-examples
中有几个程序使用subwin
和相关的derwin
,这可能对比较有用。