DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Using The Windows 7/8 Taskbar Progress Indicator Outside The WPF Stack

Denzel D. user avatar by
Denzel D.
·
Oct. 15, 12 · Interview
Like (0)
Save
Tweet
Share
9.22K Views

Join the DZone community and get the full member experience.

Join For Free

Have you seen that progress indicator in the Windows 7/8 taskbar? If you used Windows 7 or 8 at least for a day, chances are you did. Did you like it? I surely did. It is handy to see the progress of an operation right in the taskbar, without having to switch to a different window.

Implementing this in a .NET desktop application isn’t hard if you are using the Windows API Code Pack for .NET Framework (otherwise, you would have to directly use the WinAPI), given that you are working outside the boundaries of the WPF stack.

First of all, you either need to reference the Core and Shell projects (included in the Windows API Code Pack) in your application (by adding the projects to the solution and then creating proper references) or separately open the above mentioned projects and compile the DLLs. I prefer the second way, since you won’t have another two projects floating in your solution and it will be easier to handle the references later. Once you set the references, you are ready to go.

In your application, add the proper references to the Windows API Code Pack namespaces, used for this example:

using Microsoft.WindowsAPICodePack.Taskbar; 
using Microsoft.WindowsAPICodePack.Shell; 

I will put some test code in a temporary event handler - my code went in a Button_Click event in a WinForms application.

A good practice in this situation is to check whether the client machine supports the new taskbar capabilities, because chances are the application is running on an older Windows release. To do this, use the following snippet:

if (TaskbarManager.IsPlatformSupported) 
{ 
// Set of events if taskbar features are supported 
} 
else 
{
// Set of events if the taskbar features are not supported 
} 

If the taskbar is supported, you could use this snippet to test the progress indicator:

TaskbarManager tbManager = TaskbarManager.Instance; 

tbManager.SetProgressValue(50, 100); 

The first line will instantiate the taskbar, so that it can be accessed from the application. In this example, I am putting it inside the event handler. If you plan to use it somewhere else in your application, I would recommend placing it inside the class, but outside an event handler.

The second line sets the progress value to 50, also showing that the maximum value is 100. It is a static progress bar, since it is not tied to a specific event. Now, you can also set various progress bar states, depending on the state of the specific activity performed.

The Error progress state is used to represent an error with the current action:

tbManager.SetProgressState(TaskbarProgressBarState.Error); 

The Indeterminate state is used to show that there is an action either pending for some reason or awaiting user input. It is a constantly moving green bar:  

tbManager.SetProgressState(TaskbarProgressBarState.Indeterminate); 

There is also a NoProgress state, that will hide the progress. Generally, a developer can use it to hide the current progress because an action failed or because there is another reason to do so.

tbManager.SetProgressState(TaskbarProgressBarState.NoProgress); 

The Normal state is used to show the progress in its normal (green) color. Used to reset the progress bar to its default color, if that was changed, since it is the default choice anyway (if you did not change it initially.

tbManager.SetProgressState(TaskbarProgressBarState.Normal); 

And last but not least, there is the Paused state, that is a yellow progress bar, that is used to show the user that the current action is paused, either by choice or by an event.

tbManager.SetProgressState(TaskbarProgressBarState.Paused); 

As this doesn’t seem very complicated, I would like to mention that this became even easier in .NET Framework 4.0, since the taskbar handling capabilities are integrated in WPF.

Remember: you can always rely on the native APIs as well.

Windows Presentation Foundation Indicator (metadata) application

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • DevOps Roadmap for 2022
  • ChatGPT: The Unexpected API Test Automation Help
  • What Is Policy-as-Code? An Introduction to Open Policy Agent
  • Secrets Management

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: