控制台应用程序

#include <iostream>
#include <conio.h>
#include <windows.h>
#include <string.h>
#include <winuser.h>
#include <wincon.h>


HANDLE hOut ;
HANDLE hIn ;

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值