#include <windows.h>
#include <iostream>
#include <iomanip>
#include <conio.h>
using namespace std;
HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE );
COORD coord;
void SetPosition ( int x, int y ) { coord.X = x; coord.Y = y; SetConsoleCursorPosition ( handle, coord ); }
class Draw {
public:
void Load ( ) {
CONSOLE_CURSOR_INFO info = { 1, 0 };
SetConsoleCursorInfo ( handle, &info );
system ( "mode con cols=100 lines=31" );
system ( "color f0" );
SetConsoleTitle ( TEXT ( "C2D" ) );
HWND hWnd = GetConsoleWindow ( );
RECT rc;
GetWindowRect ( hWnd, &rc );
SetWindowLongPtr ( hWnd, GWL_STYLE, GetWindowLong ( hWnd, GWL_STYLE )
& ~WS_THICKFRAME & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX );
SetWindowPos ( hWnd, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, NULL );
}
void PrintRectangle ( int x, int y, int width, int height, int color ) {
SetConsoleTextAttribute ( handle, color );
for ( int i = 0; i < height; i++ ) {
SetPosition ( x, ( y + i ) );
cout << setw ( width ) << '\0';
}
}
void PrintButton ( int x, int y, int width, int height, int color, string text ) {
PrintRectangle ( x, y, width, height, color );
PrintText ( x + ( ( width - text.length ( ) ) / 2 ), y + ( height / 2 ), text );
}
void PrintText ( int x, int y, string text ) {
SetPosition ( x, y );
cout << text;
}
void Signel ( ) {
while ( 1 ) {
while ( kbhit ( ) == 0) {
if ( getch ( ) == 13 ) {
Loding ( );
}
}
}
}
void Loding ( ) {
PrintButton( 40, 15, 20, 3, 0x3f, "检测中" );
PrintRectangle ( 25, 20, 50, 1, 0x80 );
for ( int i = 0; i < 50; i ++ ) {
PrintRectangle ( 25, 20, ( 1 + i ), 1, 0xc0 );
Sleep ( 10 );
}
PrintButton ( 40, 15, 20, 3, 0x3f, "开始检测" );
for ( int i = 0; i < 25; i++ ) {
PrintRectangle ( 25, 20, ( 1 + i ), 1, 0xf0 );
PrintRectangle ( 75 - 1 * i, 20, ( 1 + i ), 1, 0xf0 );
Sleep( 1 );
}
PrintText ( 42, 20, "检测完成: 无异常" );
}
};
int main ( ) {
Draw draw;
draw.Load ( );
draw.PrintRectangle ( 0, 0, 101, 10, 0x30 );
draw.PrintButton( 40, 15, 20, 3, 0x3f, "开始检测" );
draw.Signel ( );
return 0;
}
C++【观察系列】模拟进度条
最新推荐文章于 2023-04-28 20:07:45 发布