免费注册 查看新帖 |

Chinaunix

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

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

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

§6.6  子窗口
       子窗口的创建和删除:
#include
WINDOW *subwin(WINDOW *parent, int num_of_lines, int
num_of_cols,

int start_y, int start_x);
int delwin(WINDOW
*window_to_delete);


         子窗口和新窗口的区别:子窗口不存储屏幕字符集,而是共享父窗口的,所以子窗口实际上改变了父窗口的屏幕,子窗口清除后,屏幕依旧没有变化。
         子窗口一般用于滚动。
         刷新屏幕前,父窗口必须调用touchwin。

实例:
# cat subscl.c
/*
First, the initial code section. The base window display is initialized
with some text.  */

#include
#include
#include

int main()
{
   
WINDOW *sub_window_ptr;
   
int x_loop;
   
int y_loop;
   
int counter;
   
char a_letter = '1';

   
initscr();

   
for (y_loop = 0; y_loop
      
for (x_loop = 0; x_loop
           
mvwaddch(stdscr, y_loop, x_loop, a_letter);
           
a_letter++;
           
if (a_letter > '9') a_letter = '1';
      
}
    }


/*
We now create the new scrolling subwindow
   
and, as advised, we must 'touch' the parent window before refreshing the
screen.  */

   
sub_window_ptr = subwin(stdscr, 10, 20, 10, 10);
   
scrollok(sub_window_ptr, 1);

   
touchwin(stdscr);
   
refresh();
   
sleep(1);

/*
Then we erase the contents of the subwindow, print text to it and
refresh it.
   
The scrolling text is achieved by a loop.  */

   
werase(sub_window_ptr);
   
mvwprintw(sub_window_ptr, 2, 0, "%s", "This window will
now scroll");
   
wrefresh(sub_window_ptr);
   
sleep(1);

   
for (counter = 1; counter
      
wprintw(sub_window_ptr, "%s", "This text is both wrapping
and \
                    scrolling.");
      
wrefresh(sub_window_ptr);
      
sleep(1);
    }

/*
Having finished this loop, we delete the subwindow. Then we refresh the
base screen.  */

   
delwin(sub_window_ptr);

   
touchwin(stdscr);
   
refresh();
   
sleep(1);

   
endwin();
   
exit(EXIT_SUCCESS);
}


               
               
               

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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP