void CScoreDlg::OnButton4()
{CSHProgressWnd dlg;
const DWORD dwMax = 1500;
TCHAR szMsg[256];
HRESULT hr; UpdateData(); if ( !dlg.IsValid() )
{
AfxMessageBox ( _T("Couldn't create CSHProgressWnd object. CSHProgressWnd requires IE 5 to be installed."), MB_ICONERROR );
return;
} dlg.SetTitle ( _T("Progress Dlg Title") );
dlg.SetAnimation ( IDR_PROGRESS );
dlg.SetCancelMessage ( _T("Cancel Message") );
dlg.SetLineText ( 1, _T("Unzipping some phantom files...") ); //dlg.SetAllowMinimize ( m_bShowMinimize );
//dlg.SetCalculateTime ( m_bShowTimeLeft );
//dlg.SetShowProgressBar ( m_bShowProgressBar ); hr = m_bModalDlg ? dlg.ShowModal(this) : dlg.ShowModeless(this); if ( FAILED(hr) )
{
CString s; s.Format ( _T("Couldn't show the progress window. Error returned was %lu"),
(DWORD) hr ); AfxMessageBox ( s, MB_ICONERROR );
return;
} dlg.UpdateProgress ( 0, dwMax );
dlg.ResetTimer(); for ( DWORD dw = 0;
dw < dwMax && !dlg.HasUserCanceled();
dw += 8 + rand()%10 )
{
Sleep(150); if ( dw > dwMax )
dw = dwMax; // just in case we go over the max value wsprintf ( szMsg, _T("Progress = %lu/%lu"), dw, dwMax ); dlg.SetLineText ( 2, szMsg );
dlg.UpdateProgress ( dw );
}
}
这是我的进度条函数
{CSHProgressWnd dlg;
const DWORD dwMax = 1500;
TCHAR szMsg[256];
HRESULT hr; UpdateData(); if ( !dlg.IsValid() )
{
AfxMessageBox ( _T("Couldn't create CSHProgressWnd object. CSHProgressWnd requires IE 5 to be installed."), MB_ICONERROR );
return;
} dlg.SetTitle ( _T("Progress Dlg Title") );
dlg.SetAnimation ( IDR_PROGRESS );
dlg.SetCancelMessage ( _T("Cancel Message") );
dlg.SetLineText ( 1, _T("Unzipping some phantom files...") ); //dlg.SetAllowMinimize ( m_bShowMinimize );
//dlg.SetCalculateTime ( m_bShowTimeLeft );
//dlg.SetShowProgressBar ( m_bShowProgressBar ); hr = m_bModalDlg ? dlg.ShowModal(this) : dlg.ShowModeless(this); if ( FAILED(hr) )
{
CString s; s.Format ( _T("Couldn't show the progress window. Error returned was %lu"),
(DWORD) hr ); AfxMessageBox ( s, MB_ICONERROR );
return;
} dlg.UpdateProgress ( 0, dwMax );
dlg.ResetTimer(); for ( DWORD dw = 0;
dw < dwMax && !dlg.HasUserCanceled();
dw += 8 + rand()%10 )
{
Sleep(150); if ( dw > dwMax )
dw = dwMax; // just in case we go over the max value wsprintf ( szMsg, _T("Progress = %lu/%lu"), dw, dwMax ); dlg.SetLineText ( 2, szMsg );
dlg.UpdateProgress ( dw );
}
}
这是我的进度条函数
static DWORD WINAPI AccountThreadProc(LPVOID lpParameter); //必须声明为静态的线程函数.当然如果是全局的则没这个必要cpp文件中:
DWORD WINAPI CScoreDlg::AccountThreadProc(LPVOID lpParameter)
{
CScoreDlg* pCScoreDlg=(CScoreDlg*)lpParameter;
CProgressCtrl *m_cpro=(CProgressCtrl*)pCScoreDlg->GetDlgItem(IDC_PROGRESS1); //进度条
int i=0;
while (i<100)//....处理循环长时间的工作.
{
i++;
m_cpro->SetPos(i); //设置时度条.
}
}//调用
CreateThread(0,0,CScoreDlg::AccountThreadProc,(LPVOID)this ,0,&m_dwAccountThreadId);//创建线程,并开始工作另:进度条的开销挺大的,SetPos(值)时尽量控制在一百次的调用.要不慢得要死!