Programming Windows 7: Taskbar. Part 1 - Progress Bar

    The new Windows 7 operating system contains a large number of innovations and improvements. These improvements relate to safety, performance, reliability, etc. Serious attention is also paid to the user interface. For developers of software on the Windows platform, the new OS is also of interest, because it contains elements that can be affected by software. Over the course of several posts, we will talk about the main innovations and the software model for them.



    The first thing that catches your eye when working with Windows 7 is, of course, the updated task bar. There are really a lot of conceptual changes in the new taskbar. One such change is the ability to display the progress of a task (progress bar).

    This figure clearly shows that right on the taskbar displays information about the copy process. Such 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 number of scenarios - displaying the process of conversion, copying, data generation, reporting, image generation, etc.

    From the point of view of the developer of client applications for Windows, the process of using this functionality seems quite simple. Interaction with the OS occurs at the unmanaged level, so for .NET applications, the implementation of managed wrappers is required. All of this work has already been done by Microsoft developers and put it in the .NET Interop Sample Library .

    The .NET Interop Sample Library consists of many components and demo applications. We will not dwell on each of them. It is important for us 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 WindowsFormsExtensions 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 completion of the current task. Because Since these are extension methods for the Form class, this class is passed to the method as a parameter. This is necessary in order to determine the handle of the window for which the actions are performed. We also have the opportunity to indicate the status of the progress bar. Available states:

    // процесс выполнения = 35%
    // вызов метода расширения
    WindowsFormsExtensions.SetTaskbarProgress(this, 35);
    // или так
    (this = Form)this.SetTaskbarProgress(35);




    • NoProgress - progress is not displayed
    • Indeterminate - progress bar flickers constantly
    • Normal - normal progress display
    • Error - error display
    • Paused - display pause
    • Setting the status of the progress bar is carried out 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 not difficult 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 indicate the current value of the progress bar, and we can also select its status.

    • Normal Mode
      image
    • Indeterminate Mode
      image
    • Error mode
      image
    • Paused Mode
      image


    Good luck in developing your applications for Windows 7! Sample

    Application:
    Taskbar-Progress.zip

    Also popular now: