Overlay Icon for Windows 7 taskbar Development)

Source: Internet
Author: User

When using Windows 7 for the first time, the change in the Taskbar (Taskbar) can be said to highlight me. Based on the previous Windows desktop functions, the Windows 7 taskbar adds many other features to us: Jump Lists, Window Preview, Process Bar, Overlay Icon, and so on.

 

The new taskbar makes operations more convenient and convenient. during the "Windows 7 release" activity held by the Net club, I first learned about the features of Windows 7 taskbar supported by applications. As a developer, can our applications implement these functions? The answer is yes, of course. Microsoft provides a convenient tool Windows API Code Pack for. NET Framework to help us complete these development.

This article mainly demonstrates the Overlay Icon ("Overlay Icon" is literally translated on MSDN) function. From the literal point of view, I may not quite understand what this means, in Windows 7, the UAC function adds security to the system. When the UAC starts, a shield sign (such as) is displayed on the top of the Icon of some applications. That's right. This is the Overlay Icon function, let's take a look at how it is implemented.

 

Preparations

1. Add some Overlay Icon images (. ico) to the project Resources.

2. Download the Windows API Code Pack and add Microsoft. WindowsAPICodePack. dll and Microsoft. WindowsAPICodePack. Shell. dll.

3. reference the Microsoft. WindowsAPICodePack. Taskbar namespace.

 

TaskbarManager. SetOverlayIcon (Icon, String) Method

The TaskbarManager class provides some common methods for setting taskbar features. The SetOverlayIcon method has three different ways to set the Overlay Icon:

// Used for public void SetOverlayIcon (System. Drawing. Icon, string accessibilityText) {CoreHelpers. ThrowIfNotWin7 (); TaskbarList. SetOverlayIcon (OwnerHandle,
Icon! = Null? Icon. Handle: IntPtr. Zero, accessibilityText);} // specifies the window public void SetOverlayIcon (IntPtr when whandle, System. Drawing. Icon icon,
String accessibilityText) {CoreHelpers. ThrowIfNotWin7 (); TaskbarList. SetOverlayIcon (define whandle,
Icon! = Null? Icon. Handle: IntPtr. Zero, accessibilityText);} // used to specify the public void SetOverlayIcon (System. Windows. Window window,
System. Drawing. Icon icon, string accessibilityText) {CoreHelpers. ThrowIfNotWin7 (); TaskbarList. SetOverlayIcon (new javaswinterophelper (window). Handle, icon! = Null? Icon. Handle: IntPtr. Zero, accessibilityText );}

 

Overlay Icon effect can be achieved through TaskbarManager. Instance. SetOverlayIcon () in the program:

Icon icon = iconList.SelectedItem as Icon;TaskbarManager.Instance.SetOverlayIcon(icon, "Overlay Icon Demo");

 

IfIconAndStringSetNullThe Overlay Icon effect is canceled:

TaskbarManager.Instance.SetOverlayIcon(null, null);

 

Single Window example

Status after running:


Different Effects of selecting an Overlay Icon in the Icon list:

 

Multi-Window example

By default, if a child window is called out from the parent window, its taskbar icons are combined and superimposed (for example ):

 

If you want to implement Overlay icons for different windows, you must first change the Application ID (AppID) of TestWindow to split the taskbar icons of the two windows. Each running window has its own AppID to determine which window the taskbar icon belongs. This is why the taskbar icons are automatically superimposed after we open multiple Word documents or IE labels. Therefore, we can modify the AppID of the window to display the taskbar icons separately.

You can use TaskbarManager. SetApplicationIdForSpecificWindow (IntPtr when whandle, String appID) to modify the AppID of the window. However, the currently downloaded Windows API version 1.0.1 has some minor issues, making the SetApplicationIdForSpecificWindow method ineffective at all. The root cause is TaskbarNativeMethods. the SetWindowProperty method of cs does not assign values to pv. As a result, propStore does not have a value at all, so pv is added to this method. setString (value), re-compile and replace the original Microsoft. windowsAPICodePack. shell. dll:

internal static void SetWindowProperty(IntPtr hwnd, PropertyKey propkey, 
string value){ // Get the IPropertyStore for the given window handle IPropertyStore propStore = GetWindowPropertyStore(hwnd); // Set the value PropVariant pv = new PropVariant(); pv.SetString(value); propStore.SetValue(ref propkey, ref pv); // Dispose the IPropertyStore and PropVariant Marshal.ReleaseComObject(propStore); pv.Clear();}

 

After the program is changed, you can use SetApplicationIdForSpecificWindow (IntPtr, String) to work:

Window newWindow = new TestWindow();newWindow.Show();WindowInteropHelper helper = new WindowInteropHelper(newWindow);IntPtr ptr = helper.Handle;          TaskbarManager.Instance.SetApplicationIdForSpecificWindow(ptr, "AppID");

 

After modifying the AppID of TestWindow, the taskbar icons of the two windows are truly separated:

 

SetOverlayIcon (IntPtr, Icon, String) is used to set Overlay Icon of the specified window (TestWindow:

TaskbarManager.Instance.SetOverlayIcon(ptr, icon, "Overlay Icon Demo");

 

After separation, let's take a look at the effect. Only the MainWindow icon is displayed:

The icons in both windows are displayed:

 

References

1. Windows 7 New Taskbar-An Overview

Http://channel9.msdn.com/posts/yochay/Windows-7-New-Taskbar-an-overview/

2. The Windows 7 Taskbar

Http://blogs.msdn.com/e7/archive/2008/11/20/happy-anniversary-windows-on-the-evolution-of-the-taskbar.aspx

3. Windows API Code Pack for. NET Framework

Http://code.msdn.microsoft.com/WindowsAPICodePack

4. Introducing The Taskbar APIs

Http://msdn.microsoft.com/en-us/magazine/dd942846.aspx

5. Windows 7 Taskbar Dynamic Overlay Icons and Progress Bars

Http://windowsteamblog.com/blogs/developers/archive/2009/07/28/windows-7-taskbar-dynamic-overlay-icons-and-progress-bars.aspx

6. Coding 4 Fun-Windows 7 Taskbar

Http://blogs.msdn.com/coding4fun/archive/2009/08/18/9874533.aspx

 

Source code download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.