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.
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.)