-2

I'm running ncurses on c4droid on Android. Here, box() works perfectly with window pointer of initscr() but no box of newwin().

Code:

#include <ncurses.h>

int main() {
    WINDOW * Win = initscr();
    noecho();
    crmode();
    WINDOW * win = newwin(10, 10, 1, 1);
    box(Win,0,0); // This works
    box(win,0,0); // no output
    wrefresh(win);
    refresh();
    getch();
    endwin();
}
ggorlen
  • 44,755
  • 7
  • 76
  • 106
Riyadh Kabir
  • 19
  • 1
  • 4

2 Answers2

0

The refresh() refreshes the main screen, which will clear your window. But if you remove it it still does not work. It is because getch() acts upon the main window and implicitly refreshes it. So the fix is to

  1. place refresh(); before wrefresh(win);
  2. change getch() to wgetch(win)
0

The refresh call overwrites the wrefresh, since the initscr call tells the curses library to initialize the screen before it does anything else, and because that initialization is applied to stdscr.

Changing the order would help (but also, reading from the most recent window to update helps more):

#include <ncurses.h>

int main() {
    WINDOW * Win = initscr();
    noecho();
    crmode();

    WINDOW * win = newwin(10, 10, 1, 1);
    box(Win,0,0);
    refresh();

    box(win,0,0);
    wrefresh(win);

    wgetch(win);
    endwin();
}
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105