选择显示字体大小

控制台窗口界面的编程控制(四)


  七、滚动和移动

  scrollconsolescreenbuffer是实现文本区滚动和移动的api函数。它可以将指定的一块文本区域移动到另一个区域,被移空的那块区域由指定字符填充。函数的原型如下:

bool scrollconsolescreenbuffer(
  handle hconsoleoutput, // 句柄
  const small_rect* lpscrollrectangle, // 要滚动或移动的区域
  const small_rect* lpcliprectangle, // 裁剪区域
  coord dwdestinationorigin, // 新的位置
  const char_info* lpfill // 填充字符
);

  利用这个api函数还可以实现删除指定行的操作。下面来举一个例子,程序如下:

#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);
}

  程序中,实现删除行的操作deleteline的基本原理是:首先将裁剪区域和移动区域都设置成指定行row(包括该行)以下的控制台窗口区域,然后将移动的位置指定为(0, row-1)。这样,超出裁剪区域的内容被裁剪掉,从而达到删除行的目的。

  需要说明的是,若裁剪区域参数为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   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons