In the previous article, we learned about the development of the taskbar progress bar. This article will study the thumbnail preview function. If you mention thumbnail preview, you may be familiar with Windows 7. It is a highlight of Windows 7. No matter whether the running program is active or not, you just need to move the mouse over the taskbar icon to see the preview effect of the current program. As shown in, you can quickly find the desired webpage in the IE thumbnail. Of course, many tools for developing thumbnails are also provided in the Windows API. Let's take a look at how to use them.
TabbedThumbnail. TabbedThumbnail Method
By default, Windows 7 displays the application interface (for example). If you want to replace or add a new thumbnail, first, create a new Thumbnail (Thumbnail) using the TabbedThumbnail method of the TabbedThumbnail class ).
In the TabbedThumbnail class, there are three TabbedThumbnail methods for creating thumbnails:
// Set the parent window and Child Window/control public TabbedThumbnail (IntPtr parent?whandle, IntPtr ?whandle) {if (parent=whandle = IntPtr. zero) throw new ArgumentException ("Parent window handle cannot be zero. ",
"ParentWindowHandle"); if (when whandle = IntPtr. Zero) throw new ArgumentException ("Child control's window handle cannot be zero .",
"Define whandle"); Define whandle = define whandle; parent?whandle = parent?whandle;} // set the parent window and subcontrol public partition (IntPtr parent=whandle, Control control) {if (parent=whandle = IntPtr. zero) throw new ArgumentException ("Parent window handle cannot be zero. ",
"Parent?whandle"); if (control = null) throw new ArgumentNullException ("control"); then whandle = control. handle; parent?whandle = parent=whandle;} // sets the parent Window or WPF sub-control, and the offset of the two, public TabbedThumbnail (Window parentWindow, UIElement windowsControl,
Vector peekOffset) {if (windowsControl = null) throw new ArgumentNullException ("control"); if (parentWindow = null) throw new ArgumentNullException ("parentWindow"); then whandle = IntPtr. zero; WindowsControl = windowsControl; WindowsControlParentWindow = parentWindow; parent?whandle = (new WindowInteropHelper (parentWindow )). handle; PeekOffset = peekOffset ;}
TabbedThumbnail. AddThumbnailPreview Method
Use the AddThumbnailPreview method to add TabbedThumbnail to the taskbar thumbnail:
public void AddThumbnailPreview(TabbedThumbnail preview){… …}
TabbedThumbnailManager. SetActiveTab Method
The SetActiveTab method is used to set the specified thumbnail, window handle, Form Control, and WPF control to active state. For example, if we open multiple web page tags in IE, SetActiveTab can set one of the tags to the current browser page.
public void SetActiveTab(TabbedThumbnail preview){… …}public void SetActiveTab(IntPtr windowHandle){… …}public void SetActiveTab(Control control){… …}public void SetActiveTab(UIElement windowsControl){… …}
TabbedThumbnailManager. GetThumbnailPreview Method
Use the GetThumbnailPreview method to obtain the thumbnail of the specified window handle, Form Control, and WPF control (TabbedThumbnail ):
public TabbedThumbnail GetThumbnailPreview(IntPtr windowHandle){… …}public TabbedThumbnail GetThumbnailPreview(Control control){… …}public TabbedThumbnail GetThumbnailPreview(UIElement windowsControl){… …}
TabbedThumbnailManager. RemoveThumbnailPreview Method
You can use the RemoveThumbnailPreview method to delete the specified thumbnail, window handle, Form Control, and WPF control from the taskbar thumbnail:
public void RemoveThumbnailPreview(TabbedThumbnail preview){… …}public void RemoveThumbnailPreview(IntPtr windowHandle){… …}public void RemoveThumbnailPreview(Control control){… …}public void RemoveThumbnailPreview(UIElement windowsControl){… …}
TabbedThumbnailManager. IsThumbnailPreviewAdded Method
Use the IsThumbnailPreviewAdded method to determine whether the thumbnail, window handle, Form Control, and WPF control have been added, and return the Bool value:
public bool IsThumbnailPreviewAdded(TabbedThumbnail preview){… …}public bool IsThumbnailPreviewAdded(IntPtr windowHandle){… …}public bool IsThumbnailPreviewAdded(Control control){… …}public bool IsThumbnailPreviewAdded(UIElement control){… …}
TabbedThumbnailManager. SetTabOrder Method
Use the SetTabOrder method to change the positions before and after TabbedThumbnail. Note that the first TabbedThumbnail will be switched to the front of the second TabbedThumbnail.
public void SetTabOrder(TabbedThumbnail previewToChange,
TabbedThumbnail insertBeforePreview){… …}
Effect demonstration
By using the above method, you can set the thumbnail as you like, and change the thumbnail above to the Windows Logo icon. The ui is the Name of the control in the XAML code (x: Name ):
TabbedThumbnail newPreview = new TabbedThumbnail(Application.Current.MainWindow, ui, peekOffect);TaskbarManager.Instance.TabbedThumbnail.AddThumbnailPreview(newPreview);TaskbarManager.Instance.TabbedThumbnail.SetActiveTab(newPreview);
Click "Set this image as thumbnail" Before and After comparison, and the thumbnail changes to the <Image> control:
Before ModificationAfter modification
Click "Add another thumbnail" to Add the <Button> control to the thumbnail:
Click "Change thumbnail order" to Change the front and back positions of the thumbnail:
In addition, you can use the TabbedThumbnail. Tooltip attribute to add prompt information for thumbnails. When you place the cursor over the thumbnail, the corresponding ToolTip is displayed:
newPreview.Tooltip = "Welcome to Windows 7";
References
1. Windows API Code Pack for. NET Framework
Http://code.msdn.microsoft.com/WindowsAPICodePack
2. Thumbnail Toolbars
Http://msdn.microsoft.com/en-us/library/dd378460 (VS.85). aspx # thumbbars