c++进度条代码

就当做笔记挂上面了

double flag = 50;

int countadd = 0;
int mo = 0;
 void process(double maxdata)
 {
	 vector<const char*> load{ ".\0", "..\0", "...\0" };
	 double add = flag/maxdata;
	 char arr[101] = { 0 };
	 double cnt = -1;
	 const char* table = "/-|\\";
	 while (cnt < 99)
	 {
		 double tempnext = add + cnt;
		 while (cnt!=tempnext)
		 {
			 if (tempnext >99 )
			 {
				 tempnext = 99;
			 }
			 cnt += 1;
			 if (cnt > tempnext)
			 {
				 cnt = tempnext;
			 }
			 arr[(int)cnt] = '#';
		 }
		 countadd++;
		 if (countadd ==20)
		 {
			 mo=1;
		 }
		 else if (countadd == 40)
		 {
			 mo = 2;
		 }
		 if (countadd == 60)
		 {
			 countadd = 0;
			 mo = 0;
		 }
		 printf("[%-100s][%.2f%%][%c]\r", arr, cnt + 1, table[mo]);

		 fflush(stdout);
		 Sleep(2);
	 }
 }

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Windows 平台上,可以使用 WinAPI 函数来实现进度条。下面是一个简单的示例代码,它使用了 CreateWindowEx() 函数创建了一个进度条控件,并使用了 SetWindowText() 函数设置了进度条的文本提示。 ```c #include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static HWND hProgressBar; switch (msg) { case WM_CREATE: // 创建进度条控件 hProgressBar = CreateWindowEx(0, PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE | PBS_SMOOTH, 10, 10, 200, 30, hwnd, NULL, NULL, NULL); // 设置进度条的范围 SendMessage(hProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 100)); // 设置进度条的初始值 SendMessage(hProgressBar, PBM_SETPOS, 0, 0); break; case WM_TIMER: // 模拟进度条的更新 static int nPos = 0; SendMessage(hProgressBar, PBM_SETPOS, nPos, 0); nPos += 10; if (nPos > 100) nPos = 0; break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // 创建窗口 WNDCLASSEX wc = { 0 }; wc.cbSize = sizeof(wc); wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.lpszClassName = "MyWindowClass"; RegisterClassEx(&wc); HWND hwnd = CreateWindowEx(0, "MyWindowClass", "Progress Bar Example", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 100, NULL, NULL, hInstance, NULL); // 启动定时器 SetTimer(hwnd, 1, 1000, NULL); // 显示窗口 ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); // 消息循环 MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } ``` 在上面的代码中,我们使用了一个定时器来模拟进度条的更新,每隔一秒钟进度条就会增加 10%。你可以根据自己的需要修改定时器的间隔时间和进度条的更新方式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值