曲径通幽论坛

标题: curses 相关函数 --- scroll 和 scrollok [打印本页]

作者: beyes    时间: 2009-3-22 22:25
标题: curses 相关函数 --- scroll 和 scrollok
因为屏幕默认情况下是不滚屏的,要想屏幕滚屏,就需要先用 scrollok 函数来进行设置,然后再用 scroll 来滚屏。以下为测试代码:
#include <curses.h>
#include <stdlib.h>

int main()
{
        int x_loop;
        int y_loop;
        int scroll_line;
        char a_letter = 'a';

        initscr();

        for(y_loop = 0; y_loop < 10; y_loop++) {
                for(x_loop = 0; x_loop <10; x_loop ++) {
                        mvwaddch(stdscr, y_loop, x_loop, a_letter);
                        a_letter++;
                        if(a_letter > 'z') a_letter = 'a';
                }
        }
        refresh();
        sleep(3);

        scrollok(stdscr, 1);    /*注意要先进行设置*/

        for( scroll_line = 0; scroll_line < 5; scroll_line++) {
                scroll(stdscr);
                touchwin(stdscr);
                wrefresh(stdscr);
                sleep(1);
        }

        endwin();
        exit(EXIT_SUCCESS);
}

作者: beyes    时间: 2009-3-22 22:49
标题: 测试-2
测试代码2
#include <curses.h>
#include <stdlib.h>

int main()
{
        WINDOW *win_ptr;
        int x_loop;
        int y_loop;
        int scroll_line;
        char a_letter = 'a';

        initscr();

        for(y_loop = 0; y_loop < LINES - 1; y_loop++) {
                for(x_loop = 0; x_loop < COLS; x_loop ++) {
                        mvwaddch(stdscr, y_loop, x_loop, a_letter);
                        a_letter++;
                        if(a_letter > 'z') a_letter = 'a';
                }
        }
        refresh();
        sleep(3);

        win_ptr = newwin(10, 10, 10, 10);
        //box(win_ptr, '|', '-');
        mvwprintw(win_ptr, 5, 5, "%s", "test");
        wrefresh(win_ptr);
        sleep(3);

        scrollok(win_ptr, 1);

        for( scroll_line = 0; scroll_line < 5; scroll_line++) {
                scroll(win_ptr);
                //touchwin(win_ptr);
                wrefresh(win_ptr);
                sleep(1);
        }

        delwin(win_ptr);  /*删除窗口*/
        endwin();
        exit(EXIT_SUCCESS);
}





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2