七、滚动和移动
scrollconsolescreenbuffer是实现文本区滚动和移动的api函数。它可以将指定的一块文本区域移动到另一个区域,被移空的那块区域由指定字符填充。函数的原型如下:
| bool scrollconsolescreenbuffer( handle hconsoleoutput, // 句柄 const small_rect* lpscrollrectangle, // 要滚动或移动的区域 const small_rect* lpcliprectangle, // 裁剪区域 coord dwdestinationorigin, // 新的位置 const char_info* lpfill // 填充字符 ); |
| #include #include #include handle hout; void deleteline(int row); // 删除一行 void movetext(int x, int y, small_rect rc); // 移动文本块区域 void clearscreen(void); // 清屏 void main() { hout = getstdhandle(std_output_handle); // 获取标准输出设备句柄 word att = foreground_red foreground_green foreground_intensity background_blue ; // 背景是蓝色,文本颜色是黄色 setconsoletextattribute(hout, att); clearscreen(); printf("\n\nthe soul selects her own society,\n"); printf("then shuts the door;\n"); printf("on her devine majority;\n"); printf("obtrude no more.\n\n"); console_screen_buffer_info binfo; getconsolescreenbufferinfo( hout, &binfo ); coord endpos = {0, binfo.dwsize.y - 1}; setconsolecursorposition(hout, endpos); // 设置光标位置 small_rect rc = {0, 2, 40, 5}; _getch(); movetext(10, 5, rc); _getch(); deleteline(5); closehandle(hout); // 关闭标准输出设备句柄 } void deleteline(int row) { small_rect rcscroll, rcclip; coord crdest = {0, row - 1}; char_info chfill; console_screen_buffer_info binfo; getconsolescreenbufferinfo( hout, &binfo ); rcscroll.left = 0; rcscroll.top = row; rcscroll.right = binfo.dwsize.x - 1; rcscroll.bottom = binfo.dwsize.y - 1; rcclip = rcscroll; chfill.attributes = binfo.wattributes; chfill.char.asciichar = ' '; scrollconsolescreenbuffer(hout, &rcscroll, &rcclip, crdest, &chfill); } void movetext(int x, int y, small_rect rc) { coord crdest = {x, y}; char_info chfill; console_screen_buffer_info binfo; getconsolescreenbufferinfo( hout, &binfo ); chfill.attributes = binfo.wattributes; chfill.char.asciichar = ' '; scrollconsolescreenbuffer(hout, &rc, null, crdest, &chfill); } void clearscreen(void) { console_screen_buffer_info binfo; getconsolescreenbufferinfo( hout, &binfo ); coord home = {0, 0}; word att = binfo.wattributes; unsigned long size = binfo.dwsize.x * binfo.dwsize.y; fillconsoleoutputattribute(hout, att, size, home, null); fillconsoleoutputcharacter(hout, ' ', size, home, null); } |
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器