免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 952 | 回复: 0
打印 上一主题 下一主题

《Linux 程序设计入门》 第四版 §6.5 窗口 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-12-13 17:00 |只看该作者 |倒序浏览

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

*   
WINDOW Structure
Stdscr是the 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
        for (y_loop = 0; 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
        for (y_loop = 0; 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);

               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21908/showart_1717884.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP