本文实例讲述了VC进度条的用法实例,分享给大家供大家参考。具体实现代码如下:
#include <Windows.h>
#include "resource.h"
#include <Commctrl.h>
//对话框函数
INT_PTR CALLBACK DialogProc(
__in HWND hwndDlg,
__in UINT uMsg,
__in WPARAM wParam,
__in LPARAM lParam
)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
//初始化进度条控件
HWND hWndProcess = ::GetDlgItem(hwndDlg, IDC_PROGRESS1);
//设置范围(0, 100)
::SendMessage(hWndProcess, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
//设置步进大小
::SendMessage(hWndProcess, PBM_SETSTEP, 2, 0);
//设置背景色
::SendMessage(hWndProcess, PBM_SETBKCOLOR, 0, RGB(0,0,0xff));
//设置进度条颜色
::SendMessage(hWndProcess, PBM_SETBARCOLOR, 0, RGB(0xff,0,0));
}
break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDOK:
{
//增加进度值, 增加的数值为前面设置的步长值
::SendDlgItemMessage(hwndDlg, IDC_PROGRESS1, PBM_STEPIT, 0, 0);
}
break;
case IDCANCEL:
::EndDialog(hwndDlg, IDCANCEL);
return 0;
}
}
break;
}
return 0;
}
int WINAPI WinMain(
__in HINSTANCE hInstance,
__in HINSTANCE hPrevInstance,
__in LPSTR lpCmdLine,
__in int nCmdShow
)
{
::DialogBoxParam(hInstance, (LPCTSTR)IDD_MAIN, NULL, DialogProc, NULL);
return 0;
}
希望本文所述对大家的VC++程序设计有所帮助。