如何通过NCurses的c++绑定在屏幕上显示NCursesPanel

How to show NCursesPanel on screen by c++ bindings of NCurses

本文关键字:屏幕 显示 NCursesPanel 绑定 何通过 NCurses c++      更新时间:2023-10-16

demo正在试用ncurcs -5.9附带的c++绑定。在屏幕上显示带有窗口的面板似乎并不容易。这是我的代码

class SpiderApplication : NCursesApplication
{
protected:
  int titlesize() const { return 2; };
  void title();
public:
  SpiderApplication() : NCursesApplication(TRUE) {}
  int run();
};
void SpiderApplication::title()
{
  const char * const titleText = "Demo";
  const int len = ::strlen(titleText);
  titleWindow->bkgd(screen_titles());
  titleWindow->addstr(0, (titleWindow->cols() - len) / 2, titleText);
  titleWindow->noutrefresh();
}
int SpiderApplication::run()
{
  NCursesPanel mystd;
  NCursesPanel P(mystd.lines() - titlesize(), mystd.cols(), titlesize() - 1, 0);
  P.label("Demo", NULL);
  P.show();
  ::getch();
  P.clear();
  return 0;
}

我想应该有一个面板显示在这个应用程序的标题下。然而,事实并非如此。我是不是漏掉了什么重要的东西?是否有任何例子说明如何使用c++的护士绑定?

谢谢。

我找到了我自己问题的答案。

为使面板显示在屏幕上,不能省略refresh()呼叫。下面是工作代码:

NCursesPanel mystd;
NCursesPanel P(mystd.lines() - titlesize(), mystd.cols(), titlesize() - 1, 0);
P.label("Demo", NULL);
P.show();
mystd.refresh();
::getch();
P.clear();