扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
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); } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者