/// <summary>
        /// Remove the tabbed thumbnail from the taskbar.
        /// </summary>
        /// <param name="windowsControl">TabbedThumbnail associated with the WPF Control (UIElement) that
        /// is to be removed from the taskbar</param>
        public void RemoveThumbnailPreview(UIElement windowsControl)
        {
            if (windowsControl == null)
            {
                throw new ArgumentNullException("windowsControl");
            }

            if (!_tabbedThumbnailCacheWPF.ContainsKey(windowsControl))
            {
                throw new ArgumentException(LocalizedMessages.ThumbnailManagerControlNotAdded, "windowsControl");
            }

            TaskbarWindowManager.UnregisterTab(_tabbedThumbnailCacheWPF[windowsControl].TaskbarWindow);

            _tabbedThumbnailCacheWPF.Remove(windowsControl);

            TaskbarWindow taskbarWindow = TaskbarWindowManager.GetTaskbarWindow(windowsControl, TaskbarProxyWindowType.TabbedThumbnail);

            if (taskbarWindow != null)
            {
                if (TaskbarWindowManager._taskbarWindowList.Contains(taskbarWindow))
                {
                    TaskbarWindowManager._taskbarWindowList.Remove(taskbarWindow);
                }
                taskbarWindow.Dispose();
                taskbarWindow = null;
            }
        }
        /// <summary>
        /// Adds a new tabbed thumbnail to the taskbar.
        /// </summary>
        /// <param name="preview">Thumbnail preview for a specific window handle or control. The preview
        /// object can be initialized with specific properties for the title, bitmap, and tooltip.</param>
        /// <exception cref="System.ArgumentException">If the tabbed thumbnail has already been added</exception>
        public void AddThumbnailPreview(TabbedThumbnail preview)
        {
            if (preview == null)
            {
                throw new ArgumentNullException("preview");
            }

            // UI Element has a windowHandle of zero.
            if (preview.WindowHandle == IntPtr.Zero)
            {
//                if (_tabbedThumbnailCacheWPF.ContainsKey(preview.WindowsControl))
//                {
//                    throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewAdded, "preview");
//                }
//                _tabbedThumbnailCacheWPF.Add(preview.WindowsControl, preview);
            }
            else
            {
                // Regular control with a valid handle
                if (_tabbedThumbnailCache.ContainsKey(preview.WindowHandle))
                {
                    throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewAdded, "preview");
                }
                _tabbedThumbnailCache.Add(preview.WindowHandle, preview);
            }

            TaskbarWindowManager.AddTabbedThumbnail(preview);

            preview.InvalidatePreview(); // Note: Why this here?
        }
 /// <summary>
 /// Sets the given window handle as being active on the taskbar tabbed thumbnails list.
 /// Call this method to keep the application and the taskbar in sync as to which window/control
 /// is currently active (or selected, in the case of tabbed application).
 /// </summary>
 /// <param name="windowHandle">Window handle for the control/window that is currently active in the application</param>
 /// <exception cref="System.ArgumentException">If the control/window is not yet added to the tabbed thumbnails list</exception>
 public void SetActiveTab(IntPtr windowHandle)
 {
     if (!_tabbedThumbnailCache.ContainsKey(windowHandle))
     {
         throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewNotAdded, "windowHandle");
     }
     TaskbarWindowManager.SetActiveTab(_tabbedThumbnailCache[windowHandle].TaskbarWindow);
 }
        /// <summary>
        /// Adds thumbnail toolbar for the specified window.
        /// </summary>
        /// <param name="windowHandle">Window handle for which the thumbnail toolbar buttons need to be added</param>
        /// <param name="buttons">Thumbnail buttons for the window's thumbnail toolbar</param>
        /// <exception cref="System.ArgumentException">If the number of buttons exceed the maximum allowed capacity (7).</exception>
        /// <exception cref="System.ArgumentException">If the Window Handle passed in invalid</exception>
        /// <remarks>After a toolbar has been added to a thumbnail, buttons can be altered only through various
        /// properties on the <see cref="T:Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolBarButton"/>. While individual buttons cannot be added or removed,
        /// they can be shown and hidden through <see cref="P:Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolBarButton.Visible"/> as needed.
        /// The toolbar itself cannot be removed without re-creating the window itself.
        /// </remarks>
        public void AddButtons(IntPtr windowHandle, params ThumbnailToolBarButton[] buttons)
        {
            if (windowHandle == IntPtr.Zero)
            {
                throw new ArgumentException(LocalizedMessages.ThumbnailManagerInvalidHandle, "windowHandle");
            }
            VerifyButtons(buttons);

            // Add the buttons to our window manager, which will also create a proxy window
            TaskbarWindowManager.AddThumbnailButtons(windowHandle, buttons);
        }
        /// <summary>
        /// Adds thumbnail toolbar for the specified WPF Control.
        /// </summary>
        /// <param name="control">WPF Control for which the thumbnail toolbar buttons need to be added</param>
        /// <param name="buttons">Thumbnail buttons for the window's thumbnail toolbar</param>
        /// <exception cref="System.ArgumentException">If the number of buttons exceed the maximum allowed capacity (7).</exception>
        /// <exception cref="System.ArgumentNullException">If the control passed in null</exception>
        /// <remarks>After a toolbar has been added to a thumbnail, buttons can be altered only through various
        /// properties on the ThumbnailToolBarButton. While individual buttons cannot be added or removed,
        /// they can be shown and hidden through ThumbnailToolBarButton.Visible as needed.
        /// The toolbar itself cannot be removed without re-creating the window itself.
        /// </remarks>
        public void AddButtons(UIElement control, params ThumbnailToolBarButton[] buttons)
        {
            if (control == null)
            {
                throw new ArgumentNullException(nameof(control));
            }
            VerifyButtons(buttons);

            // Add the buttons to our window manager, which will also create a proxy window
            TaskbarWindowManager.AddThumbnailButtons(control, buttons);
        }
        protected override void WndProc(ref Message m)
        {
            bool handled = TaskbarWindowManager.DispatchMessage(ref m, TaskbarWindow);

            // If it's a WM_Destroy message, then also forward it to the base class (our native window)
            if (((m.Msg == (int)WindowMessage.Destroy) ||
                 (m.Msg == (int)WindowMessage.NCDestroy) ||
                 ((m.Msg == (int)WindowMessage.SystemCommand) && (((int)m.WParam) == ScClose))) ^ !handled)
            {
                base.WndProc(ref m);
            }
        }
        /// <summary>
        /// Sets the given WPF window as being active on the taskbar tabbed thumbnails list.
        /// Call this method to keep the application and the taskbar in sync as to which window/control
        /// is currently active (or selected, in the case of tabbed application).
        /// </summary>
        /// <param name="windowsControl">WPF control that is currently active in the application</param>
        /// <exception cref="System.ArgumentException">If the control/window is not yet added to the tabbed thumbnails list</exception>
        public void SetActiveTab(UIElement windowsControl)
        {
            if (windowsControl == null)
            {
                throw new ArgumentNullException("windowsControl");
            }

            if (!_tabbedThumbnailCacheWPF.ContainsKey(windowsControl))
            {
                throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewNotAdded, "windowsControl");
            }
            TaskbarWindowManager.SetActiveTab(_tabbedThumbnailCacheWPF[windowsControl].TaskbarWindow);
        }
Beispiel #8
0
        /// <summary>
        /// Override the thumbnail and peek bitmap.
        /// By providing this bitmap manually, Thumbnail Window manager will provide the
        /// Desktop Window Manager (DWM) this bitmap instead of rendering one automatically.
        /// Use this property to update the bitmap whenever the control is updated and the user
        /// needs to be shown a new thumbnail on the taskbar preview (or aero peek).
        /// </summary>
        /// <param name="hBitmap">A bitmap handle for the image to use.
        /// <para>When the TabbedThumbnail is finalized, this class will delete the provided hBitmap.</para></param>
        /// <remarks>
        /// If the bitmap doesn't have the right dimensions, the DWM may scale it or not
        /// render certain areas as appropriate - it is the user's responsibility
        /// to render a bitmap with the proper dimensions.
        /// </remarks>
        internal void SetImage(IntPtr hBitmap)
        {
            // Before we set a new bitmap, dispose the old one
            if (CurrentHBitmap != IntPtr.Zero)
            {
                ShellNativeMethods.DeleteObject(CurrentHBitmap);
            }

            // Set the new bitmap
            CurrentHBitmap = hBitmap;

            // Let DWM know to invalidate its cached thumbnail/preview and ask us for a new one
            TaskbarWindowManager.InvalidatePreview(TaskbarWindow);
        }
//        /// <summary>
//        /// Determines whether the given control has been added to the taskbar's tabbed thumbnail list.
//        /// </summary>
//        /// <param name="control">The preview to locate on the taskbar's tabbed thumbnail list</param>
//        /// <returns>true if the tab is already added on the taskbar; otherwise, false.</returns>
//        public bool IsThumbnailPreviewAdded(UIElement control)
//        {
//            if (control == null)
//            {
//                throw new ArgumentNullException("control");
//            }
//
//            return _tabbedThumbnailCacheWPF.ContainsKey(control);
//        }

        /// <summary>
        /// Invalidates all the tabbed thumbnails. This will force the Desktop Window Manager
        /// to not use the cached thumbnail or preview or aero peek and request a new one next time.
        /// </summary>
        /// <remarks>This method should not be called frequently.
        /// Doing so can lead to poor performance as new bitmaps are created and retrieved.</remarks>
        public void InvalidateThumbnails()
        {
            // Invalidate all the previews currently in our cache.
            // This will ensure we get updated bitmaps next time

            foreach (TabbedThumbnail thumbnail in _tabbedThumbnailCache.Values)
            {
                TaskbarWindowManager.InvalidatePreview(thumbnail.TaskbarWindow);
                thumbnail.SetImage(IntPtr.Zero); // TODO: Investigate this, and why it needs to be called.
            }

//            foreach (TabbedThumbnail thumbnail in _tabbedThumbnailCacheWPF.Values)
//            {
//                TaskbarWindowManager.InvalidatePreview(thumbnail.TaskbarWindow);
//                thumbnail.SetImage(IntPtr.Zero);
//            }
        }
        protected override void WndProc(ref Message m)
        {
            var handled = false;

            if (TabbedThumbnail != null)
            {
                handled = TaskbarWindowManager.DispatchMessage(ref m, TabbedThumbnail.TaskbarWindow);
            }

            // If it's a WM_Destroy message, then also forward it to the base class (our native window)
            if ((m.Msg == (int)WindowMessage.Destroy) ||
                (m.Msg == (int)WindowMessage.NCDestroy) ||
                ((m.Msg == (int)WindowMessage.SystemCommand) && (((int)m.WParam) == TabbedThumbnailNativeMethods.ScClose)))
            {
                base.WndProc(ref m);
            }
            else if (!handled)
            {
                base.WndProc(ref m);
            }
        }
        /// <summary>
        /// Remove the tabbed thumbnail from the taskbar.
        /// </summary>
        /// <param name="windowHandle">TabbedThumbnail associated with the window handle that
        /// is to be removed from the taskbar</param>
        public void RemoveThumbnailPreview(IntPtr windowHandle)
        {
            if (!_tabbedThumbnailCache.ContainsKey(windowHandle))
            {
                throw new ArgumentException(LocalizedMessages.ThumbnailManagerControlNotAdded, "windowHandle");
            }

            TaskbarWindowManager.UnregisterTab(_tabbedThumbnailCache[windowHandle].TaskbarWindow);

            _tabbedThumbnailCache.Remove(windowHandle);

            TaskbarWindow taskbarWindow = TaskbarWindowManager.GetTaskbarWindow(windowHandle, TaskbarProxyWindowType.TabbedThumbnail);

            if (taskbarWindow != null)
            {
                if (TaskbarWindowManager._taskbarWindowList.Contains(taskbarWindow))
                {
                    TaskbarWindowManager._taskbarWindowList.Remove(taskbarWindow);
                }
                taskbarWindow.Dispose();
                taskbarWindow = null;
            }
        }
//        /// <summary>
//        /// Remove the tabbed thumbnail from the taskbar.
//        /// </summary>
//        /// <param name="windowsControl">TabbedThumbnail associated with the WPF Control (UIElement) that
//        /// is to be removed from the taskbar</param>
//        public void RemoveThumbnailPreview(UIElement windowsControl)
//        {
//            if (windowsControl == null) { throw new ArgumentNullException("windowsControl"); }
//
//            if (!_tabbedThumbnailCacheWPF.ContainsKey(windowsControl))
//            {
//                throw new ArgumentException(LocalizedMessages.ThumbnailManagerControlNotAdded, "windowsControl");
//            }
//
//            TaskbarWindowManager.UnregisterTab(_tabbedThumbnailCacheWPF[windowsControl].TaskbarWindow);
//
//            _tabbedThumbnailCacheWPF.Remove(windowsControl);
//
//            TaskbarWindow taskbarWindow = TaskbarWindowManager.GetTaskbarWindow(windowsControl, TaskbarProxyWindowType.TabbedThumbnail);
//
//            if (taskbarWindow != null)
//            {
//                if (TaskbarWindowManager._taskbarWindowList.Contains(taskbarWindow))
//                {
//                    TaskbarWindowManager._taskbarWindowList.Remove(taskbarWindow);
//                }
//                taskbarWindow.Dispose();
//                taskbarWindow = null;
//            }
//        }

        /// <summary>
        /// Sets the given tabbed thumbnail preview object as being active on the taskbar tabbed thumbnails list.
        /// Call this method to keep the application and the taskbar in sync as to which window/control
        /// is currently active (or selected, in the case of tabbed application).
        /// </summary>
        /// <param name="preview">TabbedThumbnail for the specific control/indow that is currently active in the application</param>
        /// <exception cref="System.ArgumentException">If the control/window is not yet added to the tabbed thumbnails list</exception>
        public void SetActiveTab(TabbedThumbnail preview)
        {
            if (preview == null)
            {
                throw new ArgumentNullException("preview");
            }

            if (preview.WindowHandle != IntPtr.Zero)
            {
                if (!_tabbedThumbnailCache.ContainsKey(preview.WindowHandle))
                {
                    throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewNotAdded, "preview");
                }
                TaskbarWindowManager.SetActiveTab(_tabbedThumbnailCache[preview.WindowHandle].TaskbarWindow);
            }
//            else if (preview.WindowsControl != null)
//            {
//                if (!_tabbedThumbnailCacheWPF.ContainsKey(preview.WindowsControl))
//                {
//                    throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewNotAdded, "preview");
//                }
//                TaskbarWindowManager.SetActiveTab(_tabbedThumbnailCacheWPF[preview.WindowsControl].TaskbarWindow);
//            }
        }