不确定进度条?

4
如何在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上创建一个不确定进度条,就像这样: 进度条


嗯...“但它不是我想要的无限”?那么它是什么呢?顺便说一句,快速的谷歌搜索建议你可能需要将SetPos设置为“0”。 - Jongware
没有这样的条件。因为我的进度条现在会随着使用而增加到200,然后再减少到0。 - Klasik
1个回答

3
为了创建一个不确定的进度条(称为 Marquee),您需要在对话框编辑器中将进度条的 Marquee 属性设置为 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
}

这是结果:

滚动结果


@slashp 你卡在哪里了?你尝试了什么?如果你能发布一些代码或者告诉我们更多细节会更有帮助。 - Ove
看起来我需要在我的stdafx.h中添加#pragma comment(linker,"/manifestdependency:"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='' publicKeyToken='6595b64144ccf1df' language=''""),就像这里所述:https://dev59.com/-lbTa4cB1Zd3GeqP9ESV...不过还是谢谢你的关注! - cjones26

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接