Clicco89
Clicco89

Reputation: 13

Why this window is not visible?

I've found a problem with the following code:

int ch = 0;

WINDOW *new_window(int x, int y, int w, int h)
{
    WINDOW *win;
    win = newwin(h, w, y, x);
    box(win, '|', '-');
    return win;  
}
int remove_window(WINDOW *win)
{
    delwin(win);
    refresh();
}
int showMsgbox(char *title, char *message, int x, int y, int w, int h)
{
    WINDOW *msgbox;
    msgbox = new_window(x, y, w, h);
    mvwprintw(msgbox, 0, 2, title);
    mvwprintw(msgbox, 2, 1, message);
    mvwprintw(msgbox, h, 2, "Press ENTER...");
    wrefresh(msgbox);

    while((ch = getch()) != 10) //ENTER
    {
        wrefresh(msgbox);
    }
    remove_window(msgbox);
    return 0;
}

int main()
{
    initscr();
    cbreak();
    showMsgbox("Hi!", "Hi everybody!", 2, 2, 20, 5);
    endwin();
    return 0;
}

The problem is: when I call function showMsgbox the window is not visible (There's not compiling errors/warnings/notes). Sorry if I didn't put comments. Thanks in advance!

Upvotes: 0

Views: 61

Answers (1)

Thomas Dickey
Thomas Dickey

Reputation: 54485

It is not visible because the call to getch() refreshes the top-level stdscr, which hides msgbox. If you use wgetch(msgbox), that would work more as you intended.

Upvotes: 1

Related Questions