将ProgressBar从正常切换到Marquee

Switch progressbar from normal to marquee

本文关键字:Marquee 常切换 ProgressBar      更新时间:2023-10-16

我有一个具有进度条的对话框。我不想在该对话框中添加一种方法,该对话框将进度栏设置为侯爵。我尝试以下内容:

void CDownloader::SetIntermediate(wstring info)
{
    SetDlgItemText(IDC_DOWNLOADER_LABEL, info.c_str());
    auto style = GetWindowLong(GWL_STYLE);
    style &= ~( PBS_SMOOTH | PBS_SMOOTHREVERSE | PBS_VERTICAL);
    style |= PBS_MARQUEE;
    SetWindowLong(GWL_STYLE, style);
    RECT windowRect;
    GetWindowRect(&windowRect);
    SetWindowPos(HWND_TOP, &windowRect,SWP_FRAMECHANGED);
    HWND progress = GetDlgItem(IDC_DOWNLOADER_PROGRESS);
    ::SendMessage(progress, PBM_SETMARQUEE, TRUE, 100);
}

但是这不起作用:(

我使用setWindowpos更新样式并将进度设置为Marquee。

我可以将设计师中的进度栏设置为Marquee,但不能将BAC切换为正常。

对于所有正确的代码:

void CDownloader::SetPending(bool value)
{
    if(value)
    {
        HWND progress = GetDlgItem(IDC_DOWNLOADER_PROGRESS);
        auto style = ::GetWindowLong(progress, GWL_STYLE);
        style |= PBS_MARQUEE;
        ::SetWindowLong(progress, GWL_STYLE, style);
        ::SendMessage(progress, PBM_SETMARQUEE, TRUE,0);
    }
    else
    {
        HWND progress = GetDlgItem(IDC_DOWNLOADER_PROGRESS);
        auto style = ::GetWindowLong(progress, GWL_STYLE);
        style &= ~PBS_MARQUEE;
        ::SetWindowLong(progress, GWL_STYLE, style);
        ::SendMessage(progress, PBM_SETMARQUEE, FALSE,0);
    }
}