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」)'的行爲做你所需要的行爲時,爲什麼呢? –