refresh needed instead of wrefresh?
Why this piece of code here:
#include <ncurses.h>
#define WIN 5
#define WI win[0]
#define WC win[1]
int ymax, xmax;
WINDOW *win[WIN];
int main(void)
{
int i;
initscr();
cbreak();
start_color();
curs_s开发者_StackOverflowet(0);
noecho();
init_pair(1,COLOR_GREEN,COLOR_BLACK);
getmaxyx(stdscr, ymax, xmax);
for(i=0; i<WIN; i++)
win[i]= newwin(ymax, xmax, 0, 0);
keypad(stdscr, TRUE); /* We get F1, F2 etc.. */
keypad(win[0], TRUE); /* We get F1, F2 etc.. */
refresh();
wprintw(WI, "Screen 1\n");
wprintw(WC, "Screen 2\n");
wattrset(WI, COLOR_PAIR(1));
wrefresh(WI);
getch();
endwin();
printf("\nThanks for playing\n");
return 0;
}
does not work if I delete the
refresh();
line?
Also, please, I'm new to this ncurses stuff, so if you see any other misconcept, be kind to point, specially the procedure to exit without leaving loose ends.
The problem is that one cannot mix getch()
with other windows. getch()
do a refresh()
. One should use wgetch(WI)
instead.
Still puzzles me why using the refresh()
in the begin of the code made the text appear. But I think that to understand this behavior I would need to post the entire code to see how the functions mix all the screens.
Now with wgetch()
the problem is gone.
精彩评论