闲来无聊,写了一个小时候看到其他软件经常出现的字符界面。
实现了一定的通用性,字体居中等等;逻辑上没什么难度,本来是C语言写的,由于太过无聊,又改成C++了
#include<iostream>
#include<windows.h>
#include<String.h>
#include<time.h>
#pragma comment(lib,"user32.lib")
using namespace std;
class UI{
void Pos(int x,int y);
public:
void setTime();
void surface(int x,int y,int start_x ,int start_y,WORD color);
void Information(int x,int y,string str,string author,string data,int start_x,int start_y,WORD color);
};
void UI::Pos(int x, int y){
COORD pos;
HANDLE hOutput;
pos.X = x;
pos.Y = y;
hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOutput, pos);
}
void UI::surface(int x,int y,int start_x =0,int start_y =0,WORD color=FOREGROUND_RED){
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
start_x+=csbi.dwCursorPosition.X;
start_y+=csbi.dwCursorPosit