小编use*_*911的帖子

curses库:为什么getch()清除我的屏幕?

我正在尝试使用C++学习curses库(pdcurses,因为我在Windows操作系统中).我有一个显示3个窗口的程序,然后是一个while循环,根据getch()捕获的按键进行一些处理.按下F1键时循环退出.

然而,尽管使用wrefresh()刷新所有三个窗口,但在我进入第一次按键之前没有任何内容出现.没有while循环,一切都显示正常.我做了很多测试,这就像第一次调用getch()将完全清除屏幕,而不是后续屏幕.

我的问题是:我错过了什么?起初,我在想,也许getch()调用了一个隐式的refresh(),但为什么后续调用它没有相同的行为呢?

非常感谢您的帮助.

这是代码.

#include <curses.h>

int main()
{
    initscr();
    raw();
    keypad(stdscr, TRUE);
    noecho();
    curs_set(0);

    WINDOW *wmap, *wlog, *wlegend;
    int pressed_key;
    int map_cursor_y = 10, map_cursor_x = 32;

    wlog = newwin(5, 65, 0, 15);
    wlegend = newwin(25, 15, 0, 0);
    wmap = newwin(20, 65, 5, 15);

    box(wmap, 0 , 0);
    box(wlog, 0 , 0);
    box(wlegend, 0 , 0);

    mvwprintw(wlog, 1, 1, "this is the log window");
    mvwprintw(wlegend, 1, 1, "legends");
    mvwaddch(wmap, map_cursor_y, map_cursor_x, '@');

    wrefresh(wlog);
    wrefresh(wmap);
    wrefresh(wlegend);

    while ((pressed_key …
Run Code Online (Sandbox Code Playgroud)

c++ curses getch pdcurses

7
推荐指数
2
解决办法
5238
查看次数

标签 统计

c++ ×1

curses ×1

getch ×1

pdcurses ×1