上次的进度条的方法太简陋了,运行时处理不到消息循环,当时我还不会win32控件,五年级的普通学生一个自学的当然不好。这次我用了win32控件来做,代码如下:
#include<windows.h>
#include<CommCtrl.h> //公共控件库
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")//依赖项链接
HWND hProgress;//进度条句柄
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_DESTROY:
PostQuitMessage(0);//可以使GetMessage返回0
return 0;
case WM_TIMER:{//定时器消息
SendMessage(hProgress, PBM_STEPIT, 10, 0);//移动
break;
}
case WM_CREATE:
{
//创建进度条
hProgress = CreateWindow(PROGRESS_CLASS,"",
WS_CHILD | WS_VISIBLE|PBS_SMOOTH ,/*PBS_SMOOTH是让进度条平滑的填充