bright, fresh software
Downloads  |  Buy

Wyatt Says...

October 16th, 2009

This will be another easy tip because all the work is already done and wrapped up in a nice little control. It’s open source and handles all of the details, get it here.

Progress bars in Windows 7 are nearly identical to what they were in Windows Vista. They’re green, animated and have 3 states: Normal, Error, and Paused:

Using Windows API

To get both the 3-state progress bar (regular, error, and paused) along with the taskbar progress bar we need to use some Windows API. The easier of the two to implement is changing the state of the progress bar. This works on Windows Vista and Windows 7:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);

    // 0x410 = PBM_SETSTATE
    // 0x0003 = PBST_PAUSE
    SendMessage(progressBar.Handle, 0x410, 0x0003, 0);

    // 0x0002 = PBST_ERROR
    SendMessage(progressBar.Handle, 0x410, 0x0002, 0);

    // 0x0001 = PBST_NORMAL
    SendMessage(progressBar.Handle, 0x410, 0x0001, 0);

Then there’s the matter of the taskbar progress bar in Windows 7. You can download the Windows7ProgressBar source code (zip file) to see how I did it, but the gist of it is you need to implement the ITakbarList3 Interface, and then use the SetProgressState to set the state (Normal, Error, Paused, or Marquee) and SetProgressValue to set the value.

7 Days of Windows 7

Join me Monday when I talk about Drag & Drop icons. See the full list of articles in the series.

Subscribe to Wyatt Says...

Subscribe to the 'Wyatt Says...' RSS Feed and keep up to date on on my articles on updaters, usability, open source C# components, and software licensing.

Leave a Reply