Windows 7 Taskbar Support and MFC 10

Introduction

The Windows 7 Taskbar is one of the most noticeable and useful features of the new operating system, and MFC 10 introduces a number of enhancements that make it easy to integrate the Taskbar with your application.

The Taskbar represents the central point for quick access and summary information for an application running on Windows 7. The Jump list, which is launched from the Taskbar, gives quick user access to destinations (such as documents) and tasks relevant to a particular application, and MFC Jump list development has been covered in two previous articles on basic Jump list support and advanced Shell link features. In addition to the Jump list, the Windows 7 Taskbar offers functionality for thumbnail preview of open documents, progress indication and icon overlays. This article will cover how the MFC developer can take advantage of these features.

Taskbar thumbnail support is one of the MFC 10 features that can be taken advantage of with minimal developer effort. By default, Windows 7 will generate a thumbnail preview of the entire application window. For SDI applications like Word 2007, this will give a good user experience as each running Word process will share the same Taskbar icon, and a thumbnail will be generated for each Word process, allowing the user to visually select the particular Word document they want to access. Figure 1 shows an example of this thumbnail support.


Figure 1. SDI Application Thumbnails

For MDI applications, the default taskbar thumbnail behavior is not as useful, with a single thumbnail generated for the application. This means that the user cannot switch between multiple open documents from the taskbar thumbnail, and must instead use the built-in document selection mechanism of the MDI application. To achieve a more useful taskbar thumbnail experience, applications can use the COM ITaskbarList3 interface to generate thumbnail previews for each document that the MDI application has open and the user can select the desired document to activate directly from the taskbar. Adding each MDI document to the taskbar is achieved by calling ITaskbarList3::RegisterTab, and this code is present in the MFC CMDIChildWndEx::RegisterTaskbarTab method. RegisterTaskbarTab creates a proxy window for the MDI child frame and creates a mapping of this proxy window to the parent MDI child frame Then calls ITaskbarList3::RegisterTab to add the proxy window to the taskbar.

The complexity of dealing with Taskbar thumbnails is entirely hidden if the MDI application uses the Tabbed documents style, which is the default setting for the MFC AppWizard, as shown in Figure 2. With these settings in place, the MDI thumbnail behavior shown in Figure 3 will occur. MFC will use the document and application name separated by a hyphen for the thumbnail title, and will also add a thumbnail tooltip with the same information.


Figure 2. MDI Tabbed Documents Settings


Figure 3. MFC MDI Application Thumbnail View



Windows 7 Taskbar Support and MFC 10

MFC makes it simple to add an icon overlay to the main Taskbar icon. Icon overlays are used to provide a quick visual indication of activities that are occurring in an application or the state that the application is in. A VOIP application could display an overlay indicating when the application is dialing, has a connected call, or has a call on hold. Taking up the QuickEdit sample application that has accompanied the previous articles on the Windows 7 Taskbar, icon overlays could be used to make the application more user-friendly. While the QuickEdit spell check is in progress (which for the sample application simply shows a "Spell Check In Progress" message box), an icon overlay can be added to the taskbar as shown in Figure 4.


Figure 4. QuickEdit sample application with spell check icon overlay

The code to accomplish the icon overlay is quite simple--an icon resource called IDI_ICON_CHECK was added to this project (the icon is from the excellent site IconArchive, with the specific icon used available from http://www.iconarchive.com/show/toolbar-icons-by-ruby-software/check-icon.html), and CFrameWnd::SetTaskbarOverlayIcon was called to display the icon. In the case of the sample application, the call to SetTaskbarOverlayIcon is made from the AppWizard-generated CMainFrame class, which is derived from CFrameWnd. If the call to SetTaskbarOverlayIcon needs to be made from the CDocument or CView derived class, the CWinApp::GetMainWnd method can be used to retrieve a pointer to the application's CMainFrame object, and this code is shown in the second call to SetTaskbarOverlayIcon below, which passes a NULL icon resource to remove the overlay icon.

LRESULT CMainFrame::OnSpellCheck(WPARAM wParam, LPARAM lParam)

 {

 //add the overlay icon

 SetTaskbarOverlayIcon(IDI_ICON_CHECK, L"Spell Check In Progess"); 

 

 ::AfxMessageBox(_T("Spell Check In Progress"));

 

 //remove the overlay icon

 CMainFrame* mainFrm = dynamic_cast(AfxGetApp()->GetMainWnd());

 if (mainFrm) 

 mainFrm->SetTaskbarOverlayIcon((HICON)0, L""); 

 

 return 0;

 }

The final Taskbar feature worthy of special mention is the ability to display the progress state of a lengthy operation on the Taskbar with a mini progress bar overlay. Windows 7 users will be familiar with the Taskbar progress state due to its use in Internet Explorer and Windows Explorer during file moves and downloads and it provides an excellent way to keep users updated of an application's progress without the need to Alt-Tab to the application. As with SetTaskbarOverlayIcon, the progress state MFC methods are available from CFrameWnd, and three member functions are used to control the display - SetProgressBarPosition, SetProgressBarRange and SetProgressBarState.

SetProgressBarPosition and SetProgressBarRange are used to display the familiar green progress bar overlay, but it is possible to communicate a range of other states through SetProgressBarState such as:

  • no progress (TBPF_NOPROGRESS) - which removes the progress bar)
  • indeterminate (TBPF_INDETERMINATE) - which shows a cycling progress bar)
  • normal (TBPF_NORMAL) - which displays a normal progress bar)
  • errors (TBPF_ERROR) - which displays a red progress bar
  • paused(TBPF_PAUSED) - which displays a yellow progress bar

The most comprehensive range of progress state documentation is available with the underlying COM interface ITaskbarList3::SetProgressState documentation. (http://msdn.microsoft.com/en-us/library/dd391697(VS.85).aspx).

Returning to the sample QuickEdit application, a progress bar could be displayed while the document is grammar checked, as shown in the code below. The first call sets the progress bar range to values between 0 and 100, and then a loop (with an included Sleep statement to prevent the progress bar disappearing too quickly for display purposes) increments the progress bar across the Taskbar icon for the application. The final call to SetProgressBarState hides the progress bar, indicating that the operation is complete.

LRESULT CMainFrame::OnGrammarCheck(WPARAM wParam, LPARAM lParam)

{

 SetProgressBarRange(0, 100);

 for(int ix = 0; ix < 100; ++ix){

 ::Sleep(50);

 SetProgressBarPosition(ix);

 }

 

 SetProgressBarState(TBPF_NOPROGRESS);

 

 return 0;

}

The zero to one hundred range chosen in the code sample is purely arbitrary, and any value that fits into the 32-bit parameters is acceptable.

Summary

A good way to think of the Windows 7 Taskbar is a mini remote-control and health console for applications. By providing access to the most important information about an application's status and access to the most commonly used destinations and tasks, a user's ability to fully benefit from the multi-tasking abilities of the operating system is maximized. MFC has some great updates to help the Visual C++ developer take advantage of the Taskbar, which makes an upgrade to existing applications to take advantage of these helpful new features a manageable undertaking.





Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The exponential growth of data, along with virtualization, is bringing a disruptive level of complexity to your IT infrastructure. Having multiple point solutions for data protection is not the answer, as it adds to the chaos and impedes on your ability to deliver consistent SLAs. Read this white paper to learn how a more holistic view of the infrastructure can help you to unify the data protection schemas by properly evaluating your business needs in order to gain a thorough understanding of the applications …

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds