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 );
        }

}
这是我的进度条函数

解决方案 »

  1.   

    原因:Windows是消息机而不是数据机一切事件来自于消息,而消息是一个队列,每个线程只能有一个消息对列,一个窗口只能有一个线程与之对应。在你的函数开始处理之前,一定是窗口触发了某个消息。当然,你的函数在运行时这个消息也就不可能被返回,直到你的函数结束。此时整个窗口都被“挂起”来等候你函数的返回,当然也就不可能更新了。如果你在函数中对界面有任何操作的话,都将无效。
      

  2.   

    举一个用多线程的例子:h文件中声明线程:
    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(值)时尽量控制在一百次的调用.要不慢得要死!
      

  3.   

    我要新开一个窗口,进度条完了之后,就destory it
      

  4.   

    提醒一下gxning,问问题最好还是说的清楚一点,别让大家来猜你是什么意思
      

  5.   

    sorry,我刚学,知道得不多,有时辞不达意,请大家原谅
      

  6.   

    这样,先建好一个对话框,里面有一个进度控件,CreateDialog,然后ShowWindow,在数据处理的过程序不断改变那个进度控件的值,在处理结束后EndDialog。记住,不要DoModal