Click here to Skip to main content
Email Password   helpLost your password?

Introduction 

This article describes how to use Windows 7 new taskbar features, progress indication and overlay icon, from unmanaged .NET code. The second part shows you how to manage progress indication and overlay icons in case of multiple views (windows) and provides appropriate missing classes for Windows API Code Pack.

Windows 7, New Taskbar, Progress Bar and Overlay Icon

If you look at the “What’s New” feature list on the Windows 7 official web site, the top most one is the improved taskbar.

Yes the taskbar has undergone a facelift, but there are also a number of really new key features. In this article, I’d like to treat two things: progress indication and icon overlays. Nearly each modern application which performs some activities in the background wants to notify the user without interrupting him/her that the job is done/failed or some kind of attention is needed.

Examples of Progress and Overlay icons in Windows 7 Taskbar

This screenshot shows some taskbar buttons with different progress states and overlay icons:

Do We Need It At All?

The functionality of progress indication and overlay icons is not only nice to have for applications which target Windows 7, but it is also essential for many applications which need to provide progress information in the taskbar. Most applications currently use window title which always appears in taskbar (at list its beginning). So in this case, you see usually a text “27% done”, or "New Message" on the taskbar button behind the icon of an application.

In Windows 7 per default you see only a large button with the high resolution icon on it without a caption (window title), it means the information which was communicated through window title is lost now if we do not use taskbar progress indication and overlay icon features.

How To Use It?

Windows 7 API provides appropriate methods SetOverlayIcon, SetProgressState and SetProgressValue on ITaskBarList3 interface. To enable usage of this and many other features, Microsoft provides a .NET library Windows® API Code Pack for Microsoft® .NET Framework. For more information and download see Windows® API Code Pack for Microsoft® .NET Framework under code.msdn.microsoft.com/WindowsAPICodePack.

Taskbar handling is really very easy using these .NET classes, which are provided together with C# code. For detailed step by step instructions, see Gunther Lenz's webcasts here.
Basically you need only to include projects Core and Shell into your solution and use classes Microsoft.WindowsAPICodePack.Shell.Taskbar, Microsoft.WindowsAPICodePack.Shell.Taskbar.ProgressBar, Microsoft.WindowsAPICodePack.Shell.Taskbar.OverlayIcon which are described in the supplied online documentation.
My first sample project Gma.Windows7.TaskbarDemo1 demonstrates basic progress indication and overlay icon functionality as provided by Code Pack.

How About Multiple Views?

What if we have multiple windows (forms) in the same application?
Are they able to each have their own progress and overlay icon?
How are these multiple views displayed in Windows 7 taskbar?

Having multiple windows each with individual progress is quite a common scenario; you might have several downloads running concurrently. Unfortunately (as of today) Windows API Code Pack is designed to manage a single progress bar and a single overlay icon. Although there is a class MultipleViewProgressBar and an appropriate member on Taskbar it does not provide the right behavior. I think the whole concept was misinterpreted during implementation, because you can read in online help: "MultipleViewProgressBar - Represents a taskbar button’s progress bar feature that is associated with multiple windows. Only one progress bar will get displayed on the taskbar, but states for different windows can be maintained." This is untrue. At the first sight you really need only one progress bar and overlay icon, because in Windows 7 you see only one button for all the windows of the same application. They are shown stacked, like laying upon another.

But there is an option you can change in Windows 7 taskbar properties. You can select between "Always combine, hide labels", "Combine when taskbar is full" and "Never combine". Let us select the "Never combine" option.

Windows 7 Taskbar Properties

Now we see a button per window and want to manage progress and overlay icon for each of them separately. If you look at native API, you will see that methods SetProgressState and SetProgressValue have a window handle as the first argument. It seems that the Windows API Code Pack managed wrapper reduced functionality.

Yes We Can!

My second sample project Gma.Windows7.TaskbarDemo2 uses extensions to Windows API Code Pack which enable these lost features. I hope that future versions of Code Pack will improve on that scope. The only difference between the original Code Pack and our "patched" Code pack are two additional classes Microsoft.WindowsAPICodePack.Shell.Taskbar.ProgressBarExt and Microsoft.WindowsAPICodePack.Shell.Taskbar.OverlayIconExt. They take an additional parameter in the constructor and are bound to a specific window. So you can manipulate progress state and overlays individually for each window.
These additional classes can be found under the following paths inside the downloaded ZIP file:

Code Examples

Setting progress indicator and overlay icon for the single taskbar button using Code Pack:

using Microsoft.WindowsAPICodePack.Shell.Taskbar;

...

            //Set progress to 50%
            Taskbar.ProgressBar.CurrentValue = 50; 
            //Let's show the progress strip in red 
            Taskbar.ProgressBar.State = TaskbarButtonProgressState.Error;
            //Set an overlay icon
            Taskbar.OverlayImage=new OverlayImage(new Icon("Star.ico"), "Star");

Setting progress indicators and overlay icons for multiple taskbar buttons using Code Pack extensions: Note: Do not forget to include additional classes Microsoft.WindowsAPICodePack.Shell.Taskbar.ProgressBarExt and Microsoft.WindowsAPICodePack.Shell.Taskbar.OverlayIconExt into the Shell project.

using Microsoft.WindowsAPICodePack.Shell.Taskbar;

...

            //Create an instance of a corresponding progress bar and overlay image 
            // [this] is an instance of a form which intends to manage its 
            // own state in the taskbar
            // This construction can be done only once during form construction
            ProgressBarExt ownProgressBar = new ProgressBarExt(this); 
            OverlayImageExt overlayImage = new OverlayImageExt(this);

...

            //Set progress to 50%
            ownProgressBar.CurrentValue = 50;

            //Let's show the progress strip in red 
            ownProgressBar.State = TaskbarButtonProgressState.Error;

            //Set an overlay icon
            overlayImage.Icon = new Icon("Star.ico");
            overlayImage.Text = "Star";

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralMicrosoft.WindowsAPICodePack.Shell.Taskbar namespace does not exist?
Sachin_Developer
4:10 24 Nov '09  
I am using Visual Studio 2008.
When I try to add Microsoft.WindowsAPICodePack.Shell.Taskbar, it says namespace not found.

Sky is the limit...

GeneralRe: Microsoft.WindowsAPICodePack.Shell.Taskbar namespace does not exist?
Sachin_Developer
4:36 24 Nov '09  
Problem solved.
using TaskbarManager class.

Sky is the limit...

GeneralCan we display our own dynamic bmp images on the taskbar?
midix
10:06 10 Sep '09  
Thanks for a great article.

Maybe you can help me with some problem.
I really like Windows XP Taskbar Magnifier utility which sits right on the taskbar and magnifies the desktop. I was disappointed to see that this utility is not available on Vista nor on Windows 7. As I am familiar with C++ and GDI, I hope to create some simple Taskbar Magnifier for Windows 7 but I guess this would be possible only if I can show my custom graphics on the taskbar.

So maybe you can suggest any API or some ideas where should I look? Can this be achieved just using my application taskbar icon or maybe I have to study some other ways how to draw on the taskbar?

Thanks.
AnswerRe: Can we display our own dynamic bmp images on the taskbar?
Andrew Brock
5:41 23 Nov '09  
If you have not found a solution by now, a few things i have to say about this, although i am not sure if any of these are a solution you would like:
1. Windows 7 has a full screen magnifier by using the Windows Key and + or -
2. There is an article[^] on code project that uses a DeskBand to draw onto the taskbar. This is basically the same as windows media player/iTunes. To my knowledge, Windows 7 does support this (iTunes does it on Windows 7), however I don't believe the example DeskBand I pointed you to does. This is probable what you are after tho, as when I tried that example on an XP machine i was able to drag the toolbar to the top of the screen and dock it there, then set it to always on top, so that when a window was maximized it would not go to the top of the screen, but rather to the bottom of the DeskBand.

Andrew.
GeneralThank you!
M_B_A
20:20 28 Aug '09  
Thank you for this, it is a lot easier to follow than a majority of the other tutorials on the internet, including some of the ones from Microsoft.


Last Updated 19 Jun 2009 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010