我正在创建这个简单的程序,我使用箭头键创建一个窗口,但似乎无法找到解决方案。我正在使用函数mvwin()来移动这个窗口。所有输入似乎都到达窗口,但没有动作。所有的帮助将不胜感激。
以下是代码段:
#include<ncurses.h>
WINDOW *create_newwin(int height, int width, int starty, int startx)
{
WINDOW *local_win = newwin(height, width, starty, startx);
box(local_win, 0, 0);
wprintw(local_win, "CAN YOU SEE ME MOVE");
wrefresh(local_win);
return (local_win);
}
int main()
{
char ch;
int x= 5, y= 10, h=5, wid= 20;
initscr();
noecho();
//curs_set(FALSE);
keypad(stdscr, TRUE);
cbreak();
refresh();
printw("PRINT q to EXIT\n");
WINDOW* wn= create_newwin(h, wid, x, y); //tried it directly with newwin() but nothing
//box(wn,0,0);
//wrefresh(wn);
//keypad(wn, TRUE);
//mvwin(wn, LINES/2, COLS/2);
wrefresh(wn);
while((ch=getch())!= 'q') //function to move a window
{
switch(ch)
{
case KEY_LEFT: if(x>0) --x;
break;
case KEY_RIGHT: if(x<(COLS-16)) ++x;
break;
case KEY_UP: if(y>0) --y;
break;
case KEY_DOWN: if(y<(LINES-6)) ++y;
break;
}
//wprintw(wn,"%c",ch); //to check for input
mvwin(wn, y, x);
wrefresh(wn);
// wclear(wn);
}
//wgetch(wn);
delwin(wn); //clean up window
endwin();
return 0;
}
答案 0 :(得分:2)
switch语句中有整数溢出。
将char ch
的定义更改为int ch
顶部的main
,问题就会消失。