cwinapiprogress-barcomctl32createwindowex

Marquee progress bar appears in application window, but it doesn't move


I was trying to add a PBS_MARQUEE style progress bar to my window and it does appear in the window as a legit progress bar, but when I tried to make it move using SendMessage, (animation is supposed to look like the progress bar in the Windows XP startup screen), it remained to be a grey box as it always was. If anyone out there knows how winapi c progress bars work, could you please say how to animate a marquee progress bar?

Here is the code of the progress bar being created and maybe animated using SendMessage:

case WM_CREATE:
    INITCOMMONCONTROLSEX icc = {sizeof(INITCOMMONCONTROLSEX), ICC_PROGRESS_CLASS}
    InitCommonControlsEx(&icc);

    hwndPB = CreateWindowExA(0, PROGRESS_CLASS, NULL, 
        WS_CHILD | WS_VISIBLE | PBS_MARQUEE,
        50, 200, 400, 20, hwnd, NULL, 
        ((LPCREATESTRUCT)lParam)->hInstance, NULL);

    SendMessage(hwndPB, PBM_SETMARQUEE, 1, 1000);

    UpdateWindow(hwnd);
    break;

Solution

  • A marguee-style progress bar requires ComCtl32 v6, and you must explicitly ask for v6 in your app's manifest. But, you stated in a comment that you are not doing that.

    This is mentioned in the documentation on MSDN:

    Progress Bar Control Styles

    The following control styles are supported by Progress Bar controls:

    Constant Description
    PBS_MARQUEE Version 6.0 or later. The progress indicator does not grow in size but instead moves repeatedly along the length of the bar, indicating activity without specifying what proportion of the progress is complete.
    Note: Comctl32.dll version 6 is not redistributable but it is included in Windows or later. To use Comctl32.dll version 6, specify it in a manifest. For more information on manifests, see Enabling Visual Styles.
    ... ...

    Enabling Visual Styles

    To enable your application to use visual styles, you must use ComCtl32.dll version 6 or later. Because version 6 is not redistributable, it is available only when your application is running on a version of Windows that contains it. Windows ships with both version 5 and version 6. ComCtl32.dll version 6 contains both the user controls and the common controls. By default, applications use the user controls defined in User32.dll and the common controls defined in ComCtl32.dll version 5. For a list of DLL versions and their distribution platforms, see Common Control Versions.

    If you want your application to use visual styles, you must add an application manifest or compiler directive that indicates that ComCtl32.dll version 6 should be used if it is available.

    An application manifest enables an application to specify which versions of an assembly it requires. In Microsoft Win32, an assembly is a set of DLLs and a list of versionable objects that are contained within those DLLs.

    ...

    Following is an example of a manifest file.

    Important

    Set the processorArchitecture entry to "X86" if your application targets the 32 bit Windows platform, or to "amd64" if your application targets the 64 bit Windows platform. You can also specify "*", which ensures that all platforms are targeted, as shown in the following examples.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity
        version="1.0.0.0"
        processorArchitecture="*"
        name="CompanyName.ProductName.YourApplication"
        type="win32"
    />
    <description>Your application description here.</description>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                type="win32"
                name="Microsoft.Windows.Common-Controls"
                version="6.0.0.0"
                processorArchitecture="*"
                publicKeyToken="6595b64144ccf1df"
                language="*"
            />
        </dependentAssembly>
    </dependency>
    </assembly>