2013-10-04 128 views
2

如何在MFC應用程序中創建無限不確定的進度條?不確定進度條?

有我的來源,但它不是無限的,因爲我想。

WaitProcessDlg::WaitProcessDlg(CWnd* pParent /*=NULL*/) 
    : CDialogEx(WaitProcessDlg::IDD, pParent) 
{ 

} 

void WaitProcessDlg::DoDataExchange(CDataExchange* pDX) 
{ 
    CDialogEx::DoDataExchange(pDX); 
    DDX_Control(pDX, IDC_PROGRESS1, m_Progress); 
} 


BEGIN_MESSAGE_MAP(WaitProcessDlg, CDialogEx) 
    ON_WM_TIMER() 
END_MESSAGE_MAP() 

BOOL WaitProcessDlg::OnInitDialog() 
{ 
    CDialogEx::OnInitDialog(); 

    str = pApp->GetProfileString(_T("Process"), _T("Process")); 
    if(tempHWND = ::FindWindow(NULL, str)){ 
     EndDialog(0); 
    }else{ 
     CMFCRibbonProgressBar* pProgressBar = new CMFCRibbonProgressBar(IDC_PROGRESS1, pProgressBar); 

     pProgressBar->SetInfiniteMode(m_bInfiniteProgressMode); 
     pProgressBar->SetRange(0, 200); 
     pProgressBar->SetPos(200, true); 

     m_Progress.SetInfiniteMode(m_bInfiniteProgressMode); 
     m_Progress.SetRange(0, 100); 
     SetTimer(IDC_PROGRESS1, 0, NULL); 
    } 

    return TRUE; 

} 
void WaitProcessDlg::OnTimer(UINT nIDEvent) 
{ 

    while (m_Progress.GetPos() != 100){ 
     if (tempHWND = ::FindWindow(NULL, str)){ 
      EndDialog(0); 
      KillTimer(IDC_PROGRESS1); 
     } 
      m_Progress.OffsetPos(1); 
    } 
    while (m_Progress.GetPos() != 0){ 
     if (tempHWND = ::FindWindow(NULL, str)){ 
      EndDialog(0); 
      KillTimer(IDC_PROGRESS1); 
     } 
      m_Progress.OffsetPos(-1); 
    } 
    CDialog::OnTimer(nIDEvent); 
} 

我需要如何在MFC創建一個不確定進度條,像這樣一些例子或者是什麼: Progress bar

+0

嗯。 「但它不是無限的,因爲我想要」?那麼它是什麼呢?順便說一句,快速谷歌搜索建議您可能需要將SetPos設置爲「0」。 – usr2564301

+0

沒有。沒有條件這樣做。因爲我現在的進度條一直增加到200,然後減小到0 – Klasik

回答

2

爲了創建一個不確定的進度條(稱爲選框),你需要設置您的對話框編輯器中的進度條的Marquee屬性爲True

Set Marquee to True

然後,在你InitDialog方法,你需要調用SetMarquee方法在進度條上:

BOOL CMFCApplication1Dlg::OnInitDialog() 
{ 
    CDialogEx::OnInitDialog(); 

    // Set the icon for this dialog. The framework does this automatically 
    // when the application's main window is not a dialog 
    SetIcon(m_hIcon, TRUE);   // Set big icon 
    SetIcon(m_hIcon, FALSE);  // Set small icon 

    m_Progress.SetMarquee(TRUE, 1); // Start the marquee 

    return TRUE; // return TRUE unless you set the focus to a control 
} 

下面是結果:

Marquee result

+0

非常感謝! Ove – Klasik

+0

這不適合我。有什麼建議? – slashp

+0

@slashp你卡在哪裏?你有什麼嘗試?如果您發佈一些代碼或告訴我們一些細節,這將有所幫助。 – Ove