The new operating system Windows 7 contains a large number of innovations and improvements. These improvements concern safety, performance, reliability, etc. Serious attention is also paid to the user interface. For software developers on the Windows platform, the new OS is also of interest, since it contains elements that can be acted upon programmatically. For several posts we will talk about the main innovations and the program model for them.
The first thing that catches your eye when working with Windows 7 is, of course, the updated task bar. The new taskbar has a lot of conceptual changes. One of these changes is the ability to display the progress of a task (progress bar).
')
This figure clearly shows that information on the copying process is displayed directly on the taskbar. This functionality is implemented in Windows 7 for copying files to disk, downloading data from the network (IE8). However, it is important that we can use this functionality for our applications. There can be a huge amount of scripts - displaying the process of converting, copying, generating data, building reports, generating images, etc.
From the point of view of the developer of client applications for Windows, the process of using this functionality seems quite simple. The interaction with the OS occurs at the unmanaged level, so the implementation of managed wrappers is necessary for .NET applications. All this work has already been done by developers from Microsoft and placed it in the
.NET Interop Sample Library .
The .NET Interop Sample Library consists of many components and sample applications. We will not elaborate on each of them. For us it is important that it includes the Vista Bridge Sample Library, Windows7.DesktopIntegration, and Windows7.DesktopIntegration.Registration.
The “Windows7.DesktopIntegration” project contains those classes that we need to work with the taskbar. This project includes the Windows FormsExtensions class, which contains a set of extension methods for the Form class (Windows Forms). In our case, we are interested in the following methods:
- SetTaskbarProgress (float percent)
- SetTaskbarProgressState (ThumbnailProgressState state)
Calling the first method allows you to specify the percentage of the current task. Because are extension methods for the Form class, then this class is passed to the method as a parameter. This is necessary in order to determine the handle of the window for which actions are performed.
// = 35%
//
WindowsFormsExtensions.SetTaskbarProgress(this, 35);
//
(this = Form)this.SetTaskbarProgress(35);
We also have the opportunity to indicate the status of the progress bar. Available States:
- NoProgress - no progress is displayed.
- Indeterminate - progress bar flickers constantly
- Normal - normal progress display
- Error - error display
- Paused - pause display
- The state of the progress bar is set using the second method.
WindowsFormsExtensions.SetTaskbarProgressState(this, Windows7Taskbar.ThumbnailProgressState.Normal);
//
this.SetTaskbarProgressState(Windows7Taskbar.ThumbnailProgressState.Normal);
Unfortunately, extension methods exist only for WinForms applications. However, it is easy to build a similar class for WPF applications (see the demo application).
As a result, I put together a small application that demonstrates the capabilities of the progress bar in the Windows 7 taskbar. It looks like this.

Using the control buttons, we can specify the current value of the progress bar, and we can also select its status.
- “Normal” mode

- “Indeterminate” mode

- “Error” mode

- “Paused” mode

Good luck in developing your applications for Windows 7!
Demo application:
Taskbar-Progress.zip