Hi xlordt,
I don't know what operating system and dev environment you are using but I guess it is Linux ?!? Well, I tried you run your program on my Lunix system and it doesn't work. Why? I think it's because you try to move a window with the wmove (move cursor) function in stead of the mvwin function. I'm not completely sure about this because I can't find the manual pages on my PC about this topic. Here is the code of my version:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
int main(int argc, char *argv[])
{
int ch = 0;
int x = 10;
int y = 10;
int xlen = 40;
int ylen = 10;
char msg[1024];
WINDOW *win = NULL;
initscr();
if(cbreak() == ERR || noecho() == ERR || nonl() == ERR)
{
printf("Error initializing window\n");
endwin();
return -1;
}
if((win = newwin(ylen, xlen, y, x)) == NULL)
{
printf("Error creating window\n");
endwin();
return -1;
}
curs_set(0); /* make cursor invisible */
box(win, 0, 0);
wattron(win, A_BLINK);
mvwprintw(win, 2, 2, "Press arrow keys to move window");
wattroff(win, A_BLINK);
wattron(win, A_REVERSE);
mvwprintw(win, ylen-1, 1, " Press 'q' to quit ");
wattroff(win, A_REVERSE);
keypad(win, TRUE);
while((ch = wgetch(win)) != 'q')
{
int tmpx = x;
int tmpy = y;
/* fill msg with len-2 spaces */
sprintf(msg, "%*s", xlen - 2, "");
/* clear previous line (You pressed...) */
mvwprintw(win, 4, 1, msg);
switch(ch)
{
case KEY_LEFT: tmpx--;
break;
case KEY_RIGHT: tmpx++;
break;
case KEY_UP: tmpy--;
break;
case KEY_DOWN: tmpy++;
break;
default: /* this can go wrong if key-stroke */
/* contains new-line char (e.q. F2?) */
sprintf(msg, "You pressed: [%c]", ch);
mvwprintw(win, 4, 2, msg);
break;
}
clear();
if(mvwin(win, tmpy, tmpx) == 0)
{
/* move was ok, change x and y position */
x = tmpx;
y = tmpy;
}
else
{
/* window out of screen range, display old values */
mvwin(win, y, x);
}
refresh();
}
clear();
refresh();
endwin();
return 0;
}
Maybe it's usefull for you, maybe not. But I can tell you it was a good practice for me.
Cheers,
Monster