Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19726548
  • 博文数量: 679
  • 博客积分: 10495
  • 博客等级: 上将
  • 技术积分: 9308
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-18 10:51
文章分类

全部博文(679)

文章存档

2012年(5)

2011年(38)

2010年(86)

2009年(145)

2008年(170)

2007年(165)

2006年(89)

分类: LINUX

2008-12-13 17:00:13

一般在X/Open terms “extended” curses中支持。

 

     WINDOW Structure

Stdscrthe WINDOW structure的特例。就像stdout是文件流的特例一样。

 

创建和清除窗口:

#include

WINDOW *newwin(int num_of_lines, int num_of_cols, int start_y, int start_x);

int delwin(WINDOW *window_to_delete);

     通用函数

 

函数名定义的缩写。

 

#include

int addch(const chtype char);

int waddch(WINDOW *window_pointer, const chtype char)

int mvaddch(int y, int x, const chtype char);

int mvwaddch(WINDOW *window_pointer, int y, int x, const chtype char);

int printw(char *format, ...);

int wprintw(WINDOW *window_pointer, char *format, ...);

int mvprintw(int y, int x, char *format, ...);

int mvwprintw(WINDOW *window_pointer, int y, int x, char *format, ...);

 

     移动和更新窗口

 

#include

int mvwin(WINDOW *window_to_move, int new_y, int new_x);

int wrefresh(WINDOW *window_ptr);

int wclear(WINDOW *window_ptr);

int werase(WINDOW *window_ptr);

int touchwin(WINDOW *window_ptr);

int scrollok(WINDOW *window_ptr, bool scroll_flag);

int scroll(WINDOW *window_ptr);

 

实例:管理多窗口

# cat multiw1.c

/*  As usual let's get our definitions sorted first.  */

 

#include

#include

#include

 

int main()

{

    WINDOW *new_window_ptr;

    WINDOW *popup_window_ptr;

    int x_loop;

    int y_loop;

    char a_letter = 'a';

 

    initscr();

 

/*  Then we fill the base window with characters,

    refreshing the actual screen once the logical screen has been filled:

    move(5, 5);

    printw("%s", "Testing multiple windows");

    refresh();

 

    for (x_loop = 0; x_loop < COLS - 1; x_loop++) {

        for (y_loop = 0; y_loop < LINES - 1; y_loop++) {

            mvwaddch(stdscr, y_loop, x_loop, a_letter);

            a_letter++;

            if (a_letter > 'z') a_letter = 'a';

        }

    }

 

    refresh();

    sleep(2);

 

/*  Now we create a new 10x20 window

    and add some text to it before drawing it on the screen.  */

 

    new_window_ptr = newwin(10, 20, 5, 5);

    mvwprintw(new_window_ptr, 2, 2, "%s", "Hello World");

    mvwprintw(new_window_ptr, 5, 2, "%s",

              "Notice how very long lines wrap inside the window");

 

    wrefresh(new_window_ptr);

    sleep(2);

 

/*  We now change the contents of the background window and, when we

refresh the screen, the window pointed to by new_window_ptr is obscured.  */

 

   a_letter = '0';

     for (x_loop = 0; x_loop < COLS - 1; x_loop++) {

        for (y_loop = 0; y_loop < LINES -1; y_loop++) {

            mvwaddch(stdscr, y_loop, x_loop, a_letter);

            a_letter++;

            if (a_letter > '9') a_letter = '0';

        }

    }

 

    refresh();

    sleep(2);

 

/*  If we make a call to refresh the new window, nothing will change,

    because we haven't changed the new window.  */

 

    wrefresh(new_window_ptr);

    sleep(2);

 

/*  But if we touch the window first

    and trick curses into thinking that the window has been changed.

    The next call to wrefresh will bring the new window to the front again.  */

 

    touchwin(new_window_ptr);

    wrefresh(new_window_ptr);

    sleep(2);

 

/*  Next, we add another overlapping window with a box around it.  */

 

    popup_window_ptr = newwin(10, 20, 8, 8);

    box(popup_window_ptr, '|', '-');

    mvwprintw(popup_window_ptr, 5, 2, "%s", "Pop Up Window!");

    wrefresh(popup_window_ptr);

    sleep(2);

 

/*  Then we fiddle with the new and pop-up windows before clearing and deleting them.  */

 

    touchwin(new_window_ptr);

    wrefresh(new_window_ptr);

    sleep(2);

 

    wclear(new_window_ptr);

    wrefresh(new_window_ptr);

    sleep(2);

   

    delwin(new_window_ptr);

 

    touchwin(popup_window_ptr);

    wrefresh(popup_window_ptr);

    sleep(2);

   

    delwin(popup_window_ptr);

   

    touchwin(stdscr);

    refresh();

    sleep(2);

 

    endwin();

    exit(EXIT_SUCCESS);

}

 

     自定义屏幕刷新

 

一般用于网络较慢的情况:

#include

int wnoutrefresh(WINDOW *window_ptr);

int doupdate(void);

 

阅读(4820) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~