PDA

View Full Version : ncurses - refreshing windows



BattlePanic
December 22nd, 2008, 04:42 AM
Quick question regarding ncurses. Why does the following code not display anything onscreen?


#include <ncurses.h>

int main(void)
{
WINDOW *a;

initscr();

a = newwin(0,0,0,0);

waddstr(a,"This is window A.\n");
wrefresh(a);
getch();

endwin();
return 0;
}

If I add refresh(); after initscr(); it does display the text. In other words, it seems I have to refresh the standard screen before I can draw any other window. I'm not sure why this would be. Any thoughts?

wmcbrine
December 22nd, 2008, 08:40 AM
Because your call to getch() does an implicit refresh of stdscr. Think of it as wgetch(stdscr), which is what it really is. And since the refresh of stdscr comes after the refresh of a, it overwrites it.

I'd suggest using wgetch(a) instead. You should input from the window where you want the input to appear.

BattlePanic
December 22nd, 2008, 07:30 PM
Very helpful. Thank you, wmcbrine.