我正在制作一个ncurses程序,将屏幕分成两个窗口。顶部屏幕可以接受输入,通过按'#'它会将所有文本向下移动到底部窗口并擦除顶部窗口。在我的代码中,我试图使用copywin()来替换底部窗口,但它不会在第二个窗口中粘贴措辞。这是我有...覆盖窗口
#include <ncurses.h>
int main(int argc, char *argv[])
{
// Declare variables for windows and sizes
WINDOW *top_win, *bottom_win;
int maxx, maxy, halfy, flag = 0, ch;
// Start curses
initscr();
noecho();
refresh();
// get the max x's and y's
getmaxyx(stdscr, maxy, maxx);
halfy = maxy >> 1;
// Start color
start_color();
init_pair(1, COLOR_BLACK, COLOR_WHITE);
init_pair(2, COLOR_WHITE, COLOR_CYAN);
init_pair(3, COLOR_RED, COLOR_WHITE);
// Make windows
top_win = newwin(halfy, maxx, 0, 0);
wbkgd(top_win, COLOR_PAIR(1));
wrefresh(top_win);
bottom_win = newwin(halfy, maxx, halfy, 0);
wbkgd(bottom_win, COLOR_PAIR(2));
wrefresh(bottom_win);
// Allow functions keys
keypad(top_win, TRUE);
keypad(bottom_win, TRUE);
// while loop to get input
while((ch = getch()) != '`')
{
if(ch == '@')
{
if(flag == 1)
{
flag = 0;
}
else
{
flag = 1;
}
}
else if(ch == '#')
{
//waddstr(bottom_win, "testing");
copywin(top_win, bottom_win, 0, 0, halfy, 0, halfy, maxx, TRUE);
//overwrite(top_win, bottom_win);
//werase(top_win);
}
else if(flag != 1)
{
waddch(top_win, ch | COLOR_PAIR(1));
}
else if(flag == 1)
{
waddch(top_win, ch | COLOR_PAIR(3));
}
wrefresh(top_win);
wrefresh(bottom_win);
}
// end curses
delwin(top_win);
delwin(bottom_win);
endwin();
return 0;
}
我知道我可以使用'#'字符打印到窗口,因为我的注释掉,测试语句。我也刚刚尝试使用覆盖(),但也没有工作。我只是把争论混淆了,还是其他的东西?有任何想法吗?先谢谢你!
这是很奇怪的。我猜是因为它在复制所有内容和边界时存在问题。它的工作原理,并非常感谢你了解它!我将不得不深入探讨copywin()的参数。 –
是的 - 我怀疑它是与边框有关的,但'testing'字符串出现在您期望复制的材质出现的地方。正如我所说,我没有很好的解释发生了什么事。我以(10,10)的偏移量开始,并且出现了材料。这导致最小化过程(偏移量2,1和0在10之后尝试)。如果你想出了一个很好的解释,请告诉我(例如在这里发表评论)。 –