All Your Base Are Belong To Us

Mostly .NET internals and other kinds of gory details

Windows 7 Taskbar: Thumbnail Toolbars

Let’s recap what we’ve seen so far.  We’ve started with the fundamentals of the Windows 7 taskbar APIs and the scenarios they address, reviewed the concept of application id, enriched the taskbar button with progress bars and overlay icons, and took a deep long look from all angles at the jump list, including recent/frequent categories, user tasks and custom destinations.  The next feature on our desk(top) today is thumbnail toolbars.

Thumbnail toolbars are another productivity feature that gives us the ability to do more without actually switching to another application’s window.  A thumbnail toolbar is essentially a mini remote-control that is displayed when you hover over the application’s taskbar button, right beneath the application’s thumbnail.  For example, here is the Windows Media Player thumbnail toolbar, featuring the “Play”, “Previous” and “Next” toolbar buttons.

image

A “remote control” of this sort might not be appropriate for any application, but it’s extremely handy to have.  Without interrupting your work in one application, you can easily control what another application does – no switching or tabbing need to get there.

How do you add thumbnail toolbars to your application?  As always, the managed wrappers come to the rescue.  The ThumbButtonManager class (in the Windows7.DesktopIntegration project) manages the application’s thumbnail toolbar, and allows up to 7 buttons to be added to it (this is a Windows limitation, not a limitation of the managed wrapper).  The ThumbButton class represents an individual button on the thumbnail toolbar, and exposes the Clicked event which the application can handle in response to a button click.  Other convenience properties include Enabled and Visible, which change the button’s state in real-time.  (Note that there is no way to completely remove a button after adding it.)

The following code (taken from the Windows7.DesktopIntegration.MainDemo project) demonstrates how to add a thumbnail toolbar to an application.  Note that like all other taskbar-related activities, this should be done only after receiving the “TaskbarButtonCreated” message.

_thumbButtonManager = this.CreateThumbButtonManager();

ThumbButton button2 = _thumbButtonManager.CreateThumbButton(102, SystemIcons.Exclamation, "Beware of me!");

button2.Clicked += delegate

{

    statusLabel.Text = "Second button clicked";

    button2.Enabled = false;

};

ThumbButton button = _thumbButtonManager.CreateThumbButton(101, SystemIcons.Information, "Click me");

button.Clicked += delegate

{

    statusLabel.Text = "First button clicked";

    button2.Enabled = true;

};

_thumbButtonManager.AddThumbButtons(button, button2);

Note that you have tooltips and icons at your disposal to personalize the thumbnail toolbar to your application’s needs.  All you need to do now is override your windows’ window procedure and call the DispatchMessage method of the ThumbButtonManager, so that it can correctly route the event to your registered event handlers (and of course, don’t forget to call the default window procedure when you’re done!):

if (_thumbButtonManager != null)

    _thumbButtonManager.DispatchMessage(ref m);

 

base.WndProc(ref m);

While we’re at it, let’s make note of the not-so-obvious distinction between user tasks and thumbnail toolbar buttons.  A user task within a jump list does not have context – it is always present, regardless of whether the application is currently running or whether it is engaged in some sort of activity.  On the other hand, the thumbnail toolbar is present only when the application is running, and its buttons might be disabled or even hidden – based on the current context of the application.  (E.g. it would make little sense to enable the “Next” button in a media player if there is no current playlist.)

Comments

Dew Drop - February 27, 2009 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop - February 27, 2009 | Alvin Ashcraft's Morning Dew

# February 27, 2009 3:25 PM

Sebastian said:

Hi, just wanted to drop a quick suggestion. This is unrelated to this blog post (sorry) but it's something that really bugs me about the task bar so I want to make sure someone actually considers it.

Here it goes: Clicking a task bar item should always, and immediately, open the application for that task bar item (either all its windows, or the most recently used window).

"Click" means "NOW!". Holding the button, or hovering would still bring up the little row of previews, but when the user clicks he's letting you know that he doesn't care about fine-tuning his selection, he just wants the app up front NOW.

Having to click, then scan through thumbnails, then click again in order to switch to an app is ridiculously annoying, and is single-handedly responsible for me turning off the new task bar (even though I love it in every other respect!).

If I want to switch back and forth between my mail app and e.g. Internet Explorer (to, say, copy an URL), I don't want to have to hunt around the list of tabs that comes up every time - just show me IE and whatever tab was open last will be there for me.

This is causes a severe case of "get out of my way and let me get stuff done" frustration.

# March 2, 2009 8:55 PM

Sebastian said:

Actually just letting me double-click an item to bring it up immediatly (again, either all of the windows grouped under it, or just the most recently used one) would be enough for me (though I still think that "click" means "now"). That way you're not changing the behaviour, but just giving me the option to bypass the tedious extra step when I don't need it.

# March 2, 2009 8:59 PM

All Your Base Are Belong To Us said:

Even without getting involved with the APIs, it’s clear that one of the most visually stunning features

# March 6, 2009 11:12 PM

Sasha Goldshtein said:

These are great suggestions, but I don't work for the Windows team - I'm not even a Microsoft employee.  You might want to take a look at the Engineering Windows 7 blog, where these suggestions are taken very seriously.

Note that in RC there are some changes around the taskbar which might make your experience better.

# March 6, 2009 11:16 PM

bp said:

For the total newbies, how do you include the Windows7.DesktopIntegration stuff into a project??

# March 17, 2009 4:13 PM

Sasha Goldshtein said:

Well, it's a managed class library, so you use Add Reference (in Visual Studio) and you're good to go.

Or did I get your question wrong?

# March 25, 2009 2:18 PM

Pavel Azanov said:

I'm trying to add 9 ThumbButtons to my application and show (if the user is logged in 6, if not 3) ThumbButtons. The problem is - i can't add 9 buttons, because i get an ArgumentException on the ThumbBarAddButtons method of the ITaskbarList3 interface. The solution would be: just to remove the buttons i want to make invisible. But there is no method to remove ThumbButtons! Any ideas?

# April 4, 2009 4:03 PM

Sasha Goldshtein said:

IIRC there is a hard limitation of at most 7 buttons on the thumbnail toolbar.  Additionally, there is no way to remove buttons.

# April 5, 2009 9:04 PM

Pavel Azanov said:

Thanks for the information :) I added 6 buttons and now i'm just changing the icons and the eventhandlers. But i think a function to remove buttons would be very useful^^

# April 6, 2009 3:35 PM

Sasha Goldshtein said:

@Pavel: I think so too, but it's not a limitation of the wrapper - it's the limitation of the underlying ITaskbarList3 COM interface which provides the thumbnail toolbar feature.

# April 13, 2009 7:06 PM

Talking Clipboard said:

When I make a button visible and the other one invisible, the thumbnail tool buttons does not refresh automatically, nor any refresh API provided. This causes the toolbar thumbnail to look weird

# May 30, 2009 11:46 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: