GeekIMU/4.Software/GeekIMUDriver 1.1/Src/MyCls.h

43 lines
1.3 KiB
C

#include <windows.h>
void MyCls(HANDLE hConsole)
{
COORD coordScreen = { 0, 0 };//设置清屏后光标返回的屏幕左上角坐标
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;//保存缓冲区信息
DWORD dwConSize;//当前缓冲区可容纳的字符数
bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);//获得缓冲区信息
//PERR(bSuccess, "GetConsoleScreenBufferInfo");
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;//缓冲区容纳字符数目
//用空格填充缓冲区
bSuccess = FillConsoleOutputCharacter(hConsole, (TCHAR)' ', dwConSize, coordScreen, &cCharsWritten);
//PERR(bSuccess, "FillConsoleOutputCharacter");
bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);//获得缓冲区信息
//PERR(bSuccess, "ConsoleScreenBufferInfo");
//填充缓冲区属性
bSuccess = FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
//PERR(bSuccess, "FillConsoleOutputAttribute");
//光标返回屏幕左上角坐标
bSuccess = SetConsoleCursorPosition(hConsole, coordScreen);
//printf("ok");
//PERR(bSuccess, "SetConsoleCursorPosition");
return;
}
inline void back2zero(void)
{
static HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
static COORD coordScreen = { 0, 0 };
SetConsoleCursorPosition(hStdOut, coordScreen);
}
inline void clrscr(void)
{
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
MyCls(hStdOut);
return;
}