wyDay blog  |  Downloads  |  Buy
LimeLM
wyBuild
Support forum
wyDay blog
wyDay Home

wyDay blog

October 17th, 2009

This will be another easy tip because all the work is already done and wrapped up in a nice little control. Its 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. Theyre 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); SetPaused()
{
// 0x410 = PBM_SETSTATE
// 0x0003 = PBST_PAUSE
SendMessage(progressBar.Handle, 0x410, 0x0003, 0);
} SetError()
{
// 0x0002 = PBST_ERROR
SendMessage(progressBar.Handle, 0x410, 0x0002, 0);
} SetNormal()
{
// 0x0001 = PBST_NORMAL
SendMessage(progressBar.Handle, 0x410, 0x0001, 0);
}

Then theres 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 our blog's RSS Feed or follow Wyatt (CEO of wyDay) on Mastodon (@wyatt@hachyderm.io) to keep up-to-date with our latest posts.