8
我想用ncurses.h
和多种颜色制作菜单。 我的意思是这样:在屏幕上出现多种颜色
┌────────────────────┐
│░░░░░░░░░░░░░░░░░░░░│ <- color 1
│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│ <- color 2
└────────────────────┘
但是,如果使用init_pair()
,attron()
和attroff()
整个画面的颜色是一样的,并没有像我所预料。
initscr();
init_pair(0, COLOR_BLACK, COLOR_RED);
init_pair(1, COLOR_BLACK, COLOR_GREEN);
attron(0);
printw("This should be printed in black with a red background!\n");
refresh();
attron(1);
printw("And this in a green background!\n");
refresh()
sleep(2);
endwin();
这段代码有什么问题?
感谢您的每一个答案!
而不是printw,为什么不能mvwprintw ?? –
@jorgesaraiva可能是因为没有必要吗?我的意思是,当然,你可以指定打印到哪个窗口以及你想要的位置,但是为什么当'printw(“... \ n”)'的行为做你所需要的行为时,为什么呢? –