diff --git a/trunk/ProcessHacker/Components/TaskbarLib/TaskbarClass.cs b/trunk/ProcessHacker/Components/TaskbarLib/TaskbarClass.cs index e3400a37f..ecec4a14e 100644 --- a/trunk/ProcessHacker/Components/TaskbarLib/TaskbarClass.cs +++ b/trunk/ProcessHacker/Components/TaskbarLib/TaskbarClass.cs @@ -30,198 +30,25 @@ using ProcessHacker.Native.Api; using TaskbarLib; using System.Runtime.InteropServices; -namespace TaskbarLib +public class TaskbarClass { - public class TaskbarClass - { - #region Native - - [GuidAttribute("56FDF344-FD6D-11d0-958A-006097C9A090")] - [ClassInterfaceAttribute(ClassInterfaceType.None)] - [ComImportAttribute()] - internal class TaskbarList - { } - - /// - /// ITaskbarList COM Interface - /// - [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("C43DC798-95D1-4BEA-9030-BB99E2983A1A")] - internal interface ITaskbarList - { - #region "ITaskbarList" - - /// - /// Initializes the taskbar list object. - /// This method must be called before any other ITaskbarList methods can be called. - /// - [PreserveSig] - void HrInit(); - - [PreserveSig] - void AddTab(IntPtr hwnd); - - [PreserveSig] - void DeleteTab(IntPtr hwnd); - - [PreserveSig] - void ActivateTab(IntPtr hwnd); - - [PreserveSig] - void SetActiveAlt(IntPtr hwnd); - - #endregion - - #region "ITaskbarList2" - - [PreserveSig] - void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen); - - #endregion - - #region "ITaskbarList3" - - [PreserveSig] - void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal); - - [PreserveSig] - void SetProgressState(IntPtr hwnd, TBPFlag tbpFlags); - - [PreserveSig] - void RegisterTab(IntPtr hwndTab, IntPtr hwndMDI); - - [PreserveSig] - void UnregisterTab(IntPtr hwndTab); - - [PreserveSig] - void SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore); - - [PreserveSig] - void SetTabActive(IntPtr hwndTab, IntPtr hwndInsertBefore, TBATFLAG dwReserved); - - [PreserveSig] - HRESULT ThumbBarAddButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray)] THUMBBUTTON[] pButtons); - - [PreserveSig] - HRESULT ThumbBarUpdateButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray)] THUMBBUTTON[] pButtons); - - [PreserveSig] - void ThumbBarSetImageList(IntPtr hwnd, IntPtr himl); - - [PreserveSig] - void SetOverlayIcon(IntPtr hwnd, IntPtr hIcon, [MarshalAs(UnmanagedType.LPWStr)] string pszDescription); - - [PreserveSig] - void SetThumbnailTooltip(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszTip); - - [PreserveSig] - void SetThumbnailClip(IntPtr hwnd, ref Rect prcClip); - - #endregion - - #region "ITaskbarList4" - - void SetTabProperties(IntPtr hwndTab, STPFLAG stpFlags); - - #endregion - } - - [Flags()] - public enum TBATFLAG - { - USEMDITHUMBNAIL = 1, - USEMDILIVEPREVIEW = 2 - } - [Flags()] - public enum TBPFlag - { - NOPROGRESS = 0, - INDETERMINATE = 1, - NORMAL = 2, - ERROR = 4, - PAUSED = 8 - } - [Flags()] - public enum STPFLAG - { - NONE = 0, - USEAPPTHUMBNAILALWAYS = 1, - USEAPPTHUMBNAILWHENACTIVE = 2, - USEAPPPEEKALWAYS = 4, - USEAPPPEEKWHENACTIVE = 8, - } - [Flags()] - public enum THBMASK - { - THB_BITMAP = 0x1, - THB_ICON = 0x2, - THB_TOOLTIP = 0x4, - THB_FLAGS = 0x8 - } - - [Flags()] - public enum THBFLAGS - { - THBF_ENABLED = 0x00000000, - THBF_DISABLED = 0x00000001, - THBF_DISMISSONCLICK = 0x00000002, - THBF_NOBACKGROUND = 0x00000004, - THBF_HIDDEN = 0x00000008, - THBF_NONINTERACTIVE = 0x00000010 - } - - [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Unicode)] - public struct THUMBBUTTON - { - //WPARAM value for a THUMBBUTTON being clicked. - internal const int THBN_CLICKED = 0x1800; - - [MarshalAs(UnmanagedType.U4)] - internal THBMASK dwMask; - internal uint iId; - internal uint iBitmap; - internal IntPtr hIcon; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 259)] - internal string szTip; - [MarshalAs(UnmanagedType.U4)] - internal THBFLAGS dwFlags; - } - - /// - /// HRESULT Wrapper - /// - public enum HRESULT : uint - { - S_FALSE = 0x0001, - S_OK = 0x0000, - - E_INVALIDARG = 0x80070057, - E_OUTOFMEMORY = 0x8007000E, - E_NOINTERFACE = 0x80004002, - E_FAIL = 0x80004005, - E_ELEMENTNOTFOUND = 0x80070490, - - TYPE_E_ELEMENTNOTFOUND = 0x8002802B, - NO_OBJECT = 0x800401E5, - ERROR_CANCELLED = 1223, - RESOURCE_IN_USE = 0x800700AA, - } - - #endregion - // Make this thread static because COM is not thread-safe and throws // nasty exceptions if we try to use objects created on a different // thread. [ThreadStatic] - private static ITaskbarList _taskbar = null; + private static TaskbarNative.ITaskbarList _taskbar = null; - private static ITaskbarList Taskbar + private static TaskbarNative.ITaskbarList Taskbar { get { if (_taskbar == null) { - _taskbar = (ITaskbarList)new TaskbarList(); - _taskbar.HrInit(); + _taskbar = (TaskbarNative.ITaskbarList)new TaskbarNative.TaskbarList(); + TaskbarNative.HRESULT result = _taskbar.HrInit(); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); } return _taskbar; @@ -230,85 +57,126 @@ namespace TaskbarLib public static void ActivateTab(IntPtr hwnd) { - Taskbar.ActivateTab(hwnd); + TaskbarNative.HRESULT result = Taskbar.ActivateTab(hwnd); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); } public static void AddTab(IntPtr hwnd) { - Taskbar.AddTab(hwnd); + TaskbarNative.HRESULT result = Taskbar.AddTab(hwnd); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); } public static void DeleteTab(IntPtr hwnd) { - Taskbar.DeleteTab(hwnd); + TaskbarNative.HRESULT result = Taskbar.DeleteTab(hwnd); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); } public static void SetActivateAlt(IntPtr hwnd) { - Taskbar.SetActiveAlt(hwnd); + TaskbarNative.HRESULT result = Taskbar.SetActiveAlt(hwnd); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); } public static void MarkFullscreenWindow(IntPtr hwnd, bool fullscreen) { - Taskbar.MarkFullscreenWindow(hwnd, fullscreen); + TaskbarNative.HRESULT result = Taskbar.MarkFullscreenWindow(hwnd, fullscreen); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); } public static void SetProgressValue(ulong completed, ulong total) - { - if (OSVersion.HasExtendedTaskbar) - Taskbar.SetProgressValue(Program.HackerWindowHandle, completed, total); - } - - public static void SetProgressState(TBPFlag flags) - { - if (OSVersion.HasExtendedTaskbar) - Taskbar.SetProgressState(Program.HackerWindowHandle, flags); - } - - public static void RegisterTab(IntPtr hwndTab, IntPtr hwndMDI) - { - if (OSVersion.HasExtendedTaskbar) - Taskbar.RegisterTab(hwndTab, hwndMDI); - } - - public static void UnregisterTab(IntPtr hwndTab) - { - if (OSVersion.HasExtendedTaskbar) - Taskbar.UnregisterTab(hwndTab); - } - - public static void SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore) - { - if (OSVersion.HasExtendedTaskbar) - Taskbar.SetTabOrder(hwndTab, hwndInsertBefore); - } - - public static void SetTabActive(IntPtr hwndTab, IntPtr hwndInsertBefore, TBATFLAG tbatFlags) - { - if (OSVersion.HasExtendedTaskbar) - Taskbar.SetTabActive(hwndTab, hwndInsertBefore, tbatFlags); - } - - public static void ThumbBarAddButtons(IntPtr hwnd, uint cButtons, THUMBBUTTON[] pButton) { if (OSVersion.HasExtendedTaskbar) { - HRESULT result; - - result = Taskbar.ThumbBarAddButtons(hwnd, cButtons, pButton); + TaskbarNative.HRESULT result = Taskbar.SetProgressValue(Program.HackerWindowHandle, completed, total); if (Failed(result)) throw Marshal.GetExceptionForHR((int)result); } } - public static void ThumbBarUpdateButtons(IntPtr hwnd, uint cButtons, THUMBBUTTON[] pButton) + public static void SetProgressState(TaskbarNative.TBPFlag flags) { if (OSVersion.HasExtendedTaskbar) { - HRESULT result; + TaskbarNative.HRESULT result = Taskbar.SetProgressState(Program.HackerWindowHandle, flags); - result = Taskbar.ThumbBarUpdateButtons(hwnd, cButtons, pButton); + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); + } + } + + public static void RegisterTab(IntPtr hwndTab, IntPtr hwndMDI) + { + if (OSVersion.HasExtendedTaskbar) + { + TaskbarNative.HRESULT result = Taskbar.RegisterTab(hwndTab, hwndMDI); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); + } + } + + public static void UnregisterTab(IntPtr hwndTab) + { + if (OSVersion.HasExtendedTaskbar) + { + TaskbarNative.HRESULT result = Taskbar.UnregisterTab(hwndTab); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); + } + } + + public static void SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore) + { + if (OSVersion.HasExtendedTaskbar) + { + TaskbarNative.HRESULT result = Taskbar.SetTabOrder(hwndTab, hwndInsertBefore); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); + } + } + + public static void SetTabActive(IntPtr hwndTab, IntPtr hwndInsertBefore, TaskbarNative.TBATFlag tbatFlags) + { + if (OSVersion.HasExtendedTaskbar) + { + TaskbarNative.HRESULT result = Taskbar.SetTabActive(hwndTab, hwndInsertBefore, tbatFlags); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); + } + } + + public static void ThumbBarAddButtons(IntPtr hwnd, uint cButtons, TaskbarNative.THUMBBUTTON[] pButton) + { + if (OSVersion.HasExtendedTaskbar) + { + TaskbarNative.HRESULT result = Taskbar.ThumbBarAddButtons(hwnd, cButtons, pButton); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); + } + } + + public static void ThumbBarUpdateButtons(IntPtr hwnd, uint cButtons, TaskbarNative.THUMBBUTTON[] pButton) + { + if (OSVersion.HasExtendedTaskbar) + { + TaskbarNative.HRESULT result = Taskbar.ThumbBarUpdateButtons(hwnd, cButtons, pButton); if (Failed(result)) throw Marshal.GetExceptionForHR((int)result); @@ -318,25 +186,45 @@ namespace TaskbarLib public static void ThumbBarSetImageList(IntPtr hwnd, IntPtr himl) { if (OSVersion.HasExtendedTaskbar) - Taskbar.ThumbBarSetImageList(hwnd, himl); + { + TaskbarNative.HRESULT result = Taskbar.ThumbBarSetImageList(hwnd, himl); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); + } } public static void SetOverlayIcon(Icon icon, string pszDescription) { if (OSVersion.HasExtendedTaskbar) - Taskbar.SetOverlayIcon(Program.HackerWindowHandle, icon != null ? icon.Handle : IntPtr.Zero, pszDescription); + { + TaskbarNative.HRESULT result = Taskbar.SetOverlayIcon(Program.HackerWindowHandle, icon != null ? icon.Handle : IntPtr.Zero, pszDescription); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); + } } public static void SetThumbnailTooltip(IntPtr hwnd, string pszTip) { if (OSVersion.HasExtendedTaskbar) - Taskbar.SetThumbnailTooltip(hwnd, pszTip); + { + TaskbarNative.HRESULT result = Taskbar.SetThumbnailTooltip(hwnd, pszTip); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); + } } public static void SetThumbnailClip(IntPtr hwnd, ref Rect prcClip) { if (OSVersion.HasExtendedTaskbar) - Taskbar.SetThumbnailClip(hwnd, ref prcClip); + { + TaskbarNative.HRESULT result = Taskbar.SetThumbnailClip(hwnd, ref prcClip); + + if (Failed(result)) + throw Marshal.GetExceptionForHR((int)result); + } } /// @@ -344,7 +232,7 @@ namespace TaskbarLib /// /// The error code. /// True if the error code indicates success. - public static bool Succeeded(HRESULT hresult) + public static bool Succeeded(TaskbarNative.HRESULT hresult) { return ((int)hresult >= 0); } @@ -354,10 +242,8 @@ namespace TaskbarLib /// /// The error code. /// True if the error code indicates failure. - public static bool Failed(HRESULT hResult) + public static bool Failed(TaskbarNative.HRESULT hResult) { return ((int)hResult < 0); } - } - } diff --git a/trunk/ProcessHacker/Components/TaskbarLib/TaskbarNative.cs b/trunk/ProcessHacker/Components/TaskbarLib/TaskbarNative.cs new file mode 100644 index 000000000..86d81cbe9 --- /dev/null +++ b/trunk/ProcessHacker/Components/TaskbarLib/TaskbarNative.cs @@ -0,0 +1,318 @@ +using System.Runtime.InteropServices; +using System; + +public class TaskbarNative +{ + [GuidAttribute("56FDF344-FD6D-11d0-958A-006097C9A090")] + [ClassInterfaceAttribute(ClassInterfaceType.None)] + [ComImportAttribute()] + public class TaskbarList + { } + + /// + /// ITaskbarList COM Interface + /// + [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("C43DC798-95D1-4BEA-9030-BB99E2983A1A")] + public interface ITaskbarList + { + #region "ITaskbarList" + + /// + /// Initializes the taskbar list object. + /// This method must be called before any other ITaskbarList methods can be called. + /// + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT HrInit(); + + /// + /// Adds an item to the taskbar. + /// + /// A handle to the window to be added to the taskbar. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT AddTab(IntPtr hwnd); + + /// + /// Deletes an item from the taskbar. + /// + /// A handle to the window to be deleted from the taskbar. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT DeleteTab(IntPtr hwnd); + + /// + /// Activates an item on the taskbar. The window is not actually activated; + /// the window's item on the taskbar is merely displayed as active. + /// + /// A handle to the window on the taskbar to be displayed as active. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT ActivateTab(IntPtr hwnd); + + /// + /// Marks a taskbar item as active but does not visually activate it. + /// + /// + /// SetActiveAlt marks the item associated with hwnd as the currently active + /// item for the window's process without changing the pressed state of any item. + /// Any user action that would activate a different tab in that process will + /// activate the tab associated with hwnd instead. The active state of the + /// window's item is not guaranteed to be preserved when the process associated + /// with hwnd is not active. To ensure that a given tab is always active, + /// call SetActiveAlt whenever any of your windows are activated. + /// Calling SetActiveAlt with a NULL hwnd clears this state. + /// + /// A handle to the window to be marked as active. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT SetActiveAlt(IntPtr hwnd); + + #endregion + + #region "ITaskbarList2" + + /// + /// Marks a window as full-screen. + /// + /// + /// Setting the value of fFullscreen to TRUE, the Shell treats this window as a full-screen window, + /// and the taskbar is moved to the bottom of the z-order when this window is active. + /// Setting the value of fFullscreen to FALSE removes the full-screen marking, + /// but does not cause the Shell to treat the window as though it were definitely not full-screen. + /// With a FALSEfFullscreen value, the Shell depends on its automatic detection facility to specify + /// how the window should be treated, possibly still flagging the window as full-screen. + /// + /// The handle of the window to be marked. + /// A Boolean value marking the desired full-screen status of the window. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen); + + #endregion + + #region "ITaskbarList3" + + /// + /// Displays or updates a progress bar hosted in a taskbar button to show the specific percentage completed of the full operation. + /// + /// The handle of the window whose associated taskbar button is being used as a progress indicator. + /// An application-defined value that indicates the proportion of the operation that has been completed at the time the method is called. + /// An application-defined value that specifies the value ullCompleted will have when the operation is complete + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT SetProgressValue(IntPtr hwnd, UInt64 completed, UInt64 total); + + /// + /// Sets the type and state of the progress indicator displayed on a taskbar button. + /// + /// The handle of the window in which the progress of an operation is being shown. + /// This window's associated taskbar button will display the progress bar. + /// Flags that control the current state of the progress button. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT SetProgressState(IntPtr hwnd, TBPFlag tbpFlags); + + /// + /// Informs the taskbar that a new tab or document thumbnail has been provided for display in an application's taskbar group flyout. + /// + /// Handle of the tab or document window. This value is required and cannot be NULL. + /// Handle of the application's main window. This value tells the taskbar which application's preview group to attach the new thumbnail to. This value is required and cannot be NULL. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT RegisterTab(IntPtr hwndTab, IntPtr hwndMDI); + + /// + /// Removes a thumbnail from an application's preview group when that tab or document is closed in the application. + /// + /// The handle of the tab window whose thumbnail is being removed. + /// This is the same value with which the thumbnail was registered as part the group through ITaskbarList3::RegisterTab. + /// This value is required and cannot be NULL. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT UnregisterTab(IntPtr hwndTab); + + /// + /// Inserts a new thumbnail into a tabbed-document interface (TDI) or multiple-document interface (MDI) application's group flyout or moves an existing thumbnail to a new position in the application's group. + /// + /// The handle of the tab window whose thumbnail is being placed. This value is required, must already be registered through ITaskbarList3::RegisterTab, and cannot be NULL. + /// The handle of the tab window whose thumbnail that hwndTab is inserted to the left of. This handle must already be registered through ITaskbarList3::RegisterTab. If this value is NULL, the new thumbnail is added to the end of the list. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore); + + /// + /// Informs the taskbar that a tab or document window has been made the active window. + /// + /// Handle of the active tab window. This handle must already be registered through ITaskbarList3::RegisterTab. This value can be NULL if no tab is active. + /// Handle of the application's main window. This value tells the taskbar which group the thumbnail is a member of. This value is required and cannot be NULL. + /// Reserved + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT SetTabActive(IntPtr hwndTab, IntPtr hwndInsertBefore, TBATFlag dwReserved); + + /// + /// Adds a thumbnail toolbar with a specified set of buttons to the thumbnail image of a window in a taskbar button flyout. + /// + /// The handle of the window whose thumbnail representation will receive the toolbar. This handle must belong to the calling process. + /// The number of buttons defined in the array pointed to by pButton. The maximum number of buttons allowed is 7. + /// A pointer to an array of THUMBBUTTON structures. Each THUMBBUTTON defines an individual button to be added to the toolbar. Buttons cannot be added or deleted later, so this must be the full defined set. Buttons also cannot be reordered, so their order in the array, which is the order in which they are displayed left to right, will be their permanent order. + /// Returns S_OK if successful, or an error value otherwise, including the following: + /// E_INVALIDARG - The hwnd parameter does not specify a handle that belongs to the process or does not specify a window that is associated with a taskbar button. This value is also returned if pButton is less than 1 or greater than 7. + [PreserveSig] + HRESULT ThumbBarAddButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray)] THUMBBUTTON[] pButtons); + + /// + /// Shows, enables, disables, or hides buttons in a thumbnail toolbar as required by the window's current state. A thumbnail toolbar is a toolbar embedded in a thumbnail image of a window in a taskbar button flyout. + /// + /// Because there is a limited amount of space in which to display thumbnails, + /// as well as a constantly changing number of thumbnails to display, applications are not guaranteed a specific toolbar size. + /// If display space is low, buttons in the toolbar are truncated from right to left as needed. + /// Therefore, an application should prioritize the commands associated with its buttons to ensure that those + /// of highest priority are to the left and are therefore least likely to be truncated. + /// Thumbnail toolbars are displayed only when thumbnails are being displayed on the taskbar. + /// For instance, if a taskbar button represents a group with more open windows than there is room to display thumbnails for, + /// the user interface (UI) reverts to a legacy menu rather than thumbnails. + /// The handle of the window whose thumbnail representation contains the toolbar. + /// The number of buttons defined in the array pointed to by pButton. The maximum number of buttons allowed is 7. This array contains only structures that represent existing buttons that are being updated. + /// A pointer to an array of THUMBBUTTON structures. Each THUMBBUTTON defines an individual button. If the button already exists (the iId value is already defined), then that existing button is updated with the information provided in the structure. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT ThumbBarUpdateButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray)] THUMBBUTTON[] pButtons); + + /// + /// Specifies an image list that contains button images for a toolbar embedded in a thumbnail image of a window in a taskbar button flyout. + /// + /// The handle of the window whose thumbnail representation contains the toolbar to be updated. This handle must belong to the calling process. + /// The handle of the image list that contains all button images to be used in the toolbar. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT ThumbBarSetImageList(IntPtr hwnd, IntPtr himl); + + /// + /// Applies an overlay to a taskbar button to indicate application status or a notification to the user. + /// + /// The handle of the window whose associated taskbar button receives the overlay. This handle must belong to a calling process associated with the button's application and must be a valid HWND or the call is ignored. + /// The handle of an icon to use as the overlay. This should be a small icon, measuring 16x16 pixels at 96 dots per inch (dpi). If an overlay icon is already applied to the taskbar button, that existing overlay is replaced. + /// This value can be NULL. How a NULL value is handled depends on whether the taskbar button represents a single window or a group of windows. + /// *If the taskbar button represents a single window, the overlay icon is removed from the display. + /// *If the taskbar button represents a group of windows and a previous overlay is still available (received earlier than the current overlay, but not yet freed by a NULL value), then that previous overlay is displayed in place of the current overlay. + /// It is the responsibility of the calling application to free hIcon when it is no longer needed. This can generally be done after you've called SetOverlayIcon because the taskbar makes and uses its own copy of the icon. + /// A pointer to a string that provides an alt text version of the information conveyed by the overlay, for accessibility purposes. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT SetOverlayIcon(IntPtr hwnd, IntPtr hIcon, [MarshalAs(UnmanagedType.LPWStr)] string description); + + /// + /// Specifies or updates the text of the tooltip that is displayed when the mouse pointer rests on an individual preview thumbnail in a taskbar button flyout. + /// + /// The handle to the window whose thumbnail displays the tooltip. This handle must belong to the calling process. + /// The pointer to the text to be displayed in the tooltip. This value can be NULL, in which case the title of the window specified by hwnd is used as the tooltip. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT SetThumbnailTooltip(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string tip); + + /// + /// Selects a portion of a window's client area to display as that window's thumbnail in the taskbar. + /// + /// The handle to a window represented in the taskbar. + /// A pointer to a RECT structure that specifies a selection within the window's client area, relative to the upper-left corner of that client area. To clear a clip that is already in place and return to the default display of the thumbnail, set this parameter to NULL. + /// Returns S_OK if successful, or an error value otherwise. + [PreserveSig] + HRESULT SetThumbnailClip(IntPtr hwnd, ref ProcessHacker.Native.Api.Rect prcClip); + + #endregion + + #region "ITaskbarList4" + + /// + /// Allows a tab to specify whether the main application frame window or the tab window should be used as a thumbnail or in the peek feature under certain circumstances. + /// + /// The handle of the tab window that is to have properties set. This handle must already be registered through ITaskbarList3::RegisterTab. + /// One or more members of the STPFLAG enumeration that specify the displayed thumbnail and peek image source of the tab thumbnail. + /// Returns S_OK if successful, or an error value otherwise. + HRESULT SetTabProperties(IntPtr hwndTab, STPFlag stpFlags); + + #endregion + } + + [Flags()] + public enum TBATFlag + { + USEMDITHUMBNAIL = 1, + USEMDILIVEPREVIEW = 2 + } + [Flags()] + public enum TBPFlag + { + NOPROGRESS = 0, + INDETERMINATE = 1, + NORMAL = 2, + ERROR = 4, + PAUSED = 8 + } + [Flags()] + public enum STPFlag + { + NONE = 0, + USEAPPTHUMBNAILALWAYS = 1, + USEAPPTHUMBNAILWHENACTIVE = 2, + USEAPPPEEKALWAYS = 4, + USEAPPPEEKWHENACTIVE = 8, + } + [Flags()] + public enum THBMask + { + BITMAP = 0x1, + ICON = 0x2, + TOOLTIP = 0x4, + FLAGS = 0x8 + } + [Flags()] + public enum THBFlags + { + ENABLED = 0x00000000, + DISABLED = 0x00000001, + DISMISSONCLICK = 0x00000002, + NOBACKGROUND = 0x00000004, + HIDDEN = 0x00000008, + NONINTERACTIVE = 0x00000010 + } + + [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Unicode)] + public struct THUMBBUTTON + { + //WPARAM value for a THUMBBUTTON being clicked. + internal const int THBN_CLICKED = 0x1800; + + [MarshalAs(UnmanagedType.U4)] + internal THBMask dwMask; + internal uint iId; + internal uint iBitmap; + internal IntPtr hIcon; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 259)] + internal string szTip; + [MarshalAs(UnmanagedType.U4)] + internal THBFlags dwFlags; + } + + /// + /// Native HResult Wrapper + /// + public enum HRESULT : uint + { + S_FALSE = 0x0001, + S_OK = 0x0000, + + E_INVALIDARG = 0x80070057, + E_OUTOFMEMORY = 0x8007000E, + E_NOINTERFACE = 0x80004002, + E_FAIL = 0x80004005, + E_ELEMENTNOTFOUND = 0x80070490, + + TYPE_E_ELEMENTNOTFOUND = 0x8002802B, + NO_OBJECT = 0x800401E5, + ERROR_CANCELLED = 1223, + RESOURCE_IN_USE = 0x800700AA, + } +} \ No newline at end of file diff --git a/trunk/ProcessHacker/Components/TaskbarLib/ThumbnailBarButton.cs b/trunk/ProcessHacker/Components/TaskbarLib/ThumbnailBarButton.cs index c1be17e80..c170a3955 100644 --- a/trunk/ProcessHacker/Components/TaskbarLib/ThumbnailBarButton.cs +++ b/trunk/ProcessHacker/Components/TaskbarLib/ThumbnailBarButton.cs @@ -2,28 +2,27 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using System.Drawing; -namespace TaskbarLib -{ +using TaskbarLib; + +/// +/// Represents a thumbnail toolbar button. +/// +public class ThumbnailBarButton : ThumbnailBarButtonBase +{ + private Bitmap icon; + private uint imageIndex; + /// - /// Represents a thumbnail toolbar button. + /// Initializes a with a Bitmap icon. /// - public class ThumbnailBarButton : ThumbnailBarButtonBase - { - private Bitmap icon; - - private uint imageIndex; - - /// - /// Initializes a with a Bitmap icon. - /// - /// Icon of the button. - /// Tooltip of the button. - /// Specifies whether button is hidden initially. - /// Specifies whether button is disabled initially. - /// Specifies whether button is dismissed on click. - /// Specifies whether button has background. - public ThumbnailBarButton(Bitmap icon, string tooltip, bool isHidden, bool isDisabled, bool isDismissedOnClick, bool hasBackground) - : base(tooltip, isHidden, isDisabled, isDismissedOnClick, hasBackground) + /// Icon of the button. + /// Tooltip of the button. + /// Specifies whether button is hidden initially. + /// Specifies whether button is disabled initially. + /// Specifies whether button is dismissed on click. + /// Specifies whether button has background. + public ThumbnailBarButton(Bitmap icon, string tooltip, bool isHidden, bool isDisabled, bool isDismissedOnClick, bool hasBackground) + : base(tooltip, isHidden, isDisabled, isDismissedOnClick, hasBackground) { this.icon = icon; if (icon != null) @@ -32,25 +31,25 @@ namespace TaskbarLib } } - /// - /// Initializes a with an icon resides in an . - /// - /// Index of the image from associated . - /// Tooltip of the button. - /// Specifies whether button is hidden initially. - /// Specifies whether button is disabled initially. - /// Specifies whether button is dismissed on click. - /// Specifies whether button has background. - public ThumbnailBarButton(uint imageIndex, string tooltip, bool isHidden, bool isDisabled, bool isDismissedOnClick, bool hasBackground) - : base(tooltip, isHidden, isDisabled, isDismissedOnClick, hasBackground) + /// + /// Initializes a with an icon resides in an . + /// + /// Index of the image from associated . + /// Tooltip of the button. + /// Specifies whether button is hidden initially. + /// Specifies whether button is disabled initially. + /// Specifies whether button is dismissed on click. + /// Specifies whether button has background. + public ThumbnailBarButton(uint imageIndex, string tooltip, bool isHidden, bool isDisabled, bool isDismissedOnClick, bool hasBackground) + : base(tooltip, isHidden, isDisabled, isDismissedOnClick, hasBackground) { this.imageIndex = imageIndex; } - - /// - /// A icon for button. - /// - public Bitmap Icon + + /// + /// A icon for button. + /// + public Bitmap Icon { get { @@ -69,11 +68,11 @@ namespace TaskbarLib this.Update(); } } - - /// - /// index of the the image that will be used as button icon. - /// - public uint ImageIndex + + /// + /// index of the the image that will be used as button icon. + /// + public uint ImageIndex { get { @@ -87,15 +86,13 @@ namespace TaskbarLib this.Update(); } } - - internal override void BeforeGetUnmanagedButton(ref TaskbarClass.THUMBBUTTON button) - { - button.iBitmap = this.imageIndex; - - button.dwMask |= TaskbarClass.THBMASK.THB_BITMAP; - } - - protected override void Update() - { } + + internal override void BeforeGetUnmanagedButton(ref TaskbarNative.THUMBBUTTON button) + { + button.iBitmap = this.imageIndex; + button.dwMask |= TaskbarNative.THBMask.BITMAP; } + + protected override void Update() + { } } \ No newline at end of file diff --git a/trunk/ProcessHacker/Components/TaskbarLib/ThumbnailBarButtonBase.cs b/trunk/ProcessHacker/Components/TaskbarLib/ThumbnailBarButtonBase.cs index a638eeecb..2d76cd0eb 100644 --- a/trunk/ProcessHacker/Components/TaskbarLib/ThumbnailBarButtonBase.cs +++ b/trunk/ProcessHacker/Components/TaskbarLib/ThumbnailBarButtonBase.cs @@ -1,31 +1,30 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; -namespace TaskbarLib -{ - /// - /// Represents a thumbnail toolbar button. - /// - public abstract class ThumbnailBarButtonBase : IDisposable - { - private static Dictionary idCounters; - private uint id; - private bool isDisabled; - private bool isDismissedOnClick; - private bool hasBackground; - private bool isHidden; - private string tooltip; +/// +/// Represents a thumbnail toolbar button. +/// +public abstract class ThumbnailBarButtonBase : IDisposable +{ + private static Dictionary idCounters; + + private uint id; + private bool isDisabled; + private bool isDismissedOnClick; + private bool hasBackground; + private bool isHidden; + private string tooltip; - private SafeHandle iconHandle; - private IntPtr windowHandle; - - static ThumbnailBarButtonBase() + private SafeHandle iconHandle; + private IntPtr windowHandle; + + static ThumbnailBarButtonBase() { idCounters = new Dictionary(); } - - protected ThumbnailBarButtonBase(string tooltip, bool isHidden, bool isDisabled, bool isDismissedOnClick, bool hasBackground) + + protected ThumbnailBarButtonBase(string tooltip, bool isHidden, bool isDisabled, bool isDismissedOnClick, bool hasBackground) { this.isHidden = isHidden; this.isDisabled = isDisabled; @@ -34,23 +33,23 @@ namespace TaskbarLib this.tooltip = tooltip; } - /// - /// Finalizer for type. - /// - ~ThumbnailBarButtonBase() + /// + /// Finalizer for type. + /// + ~ThumbnailBarButtonBase() { this.Dispose(false); } - - /// - /// Occurs when button is clicked. - /// - public event EventHandler Click; - - /// - /// Specifies whether button is disabled. - /// - public bool IsDisabled + + /// + /// Occurs when button is clicked. + /// + public event EventHandler Click; + + /// + /// Specifies whether button is disabled. + /// + public bool IsDisabled { get { @@ -64,11 +63,11 @@ namespace TaskbarLib this.Update(); } } - - /// - /// Specifies whether button is dismissed after click. - /// - public bool IsDismissedOnClick + + /// + /// Specifies whether button is dismissed after click. + /// + public bool IsDismissedOnClick { get { @@ -82,11 +81,11 @@ namespace TaskbarLib this.Update(); } } - - /// + + /// /// Specifies whether button has background. /// - public bool HasBackground + public bool HasBackground { get { @@ -100,11 +99,11 @@ namespace TaskbarLib this.Update(); } } - - /// - /// Specifies whether button is hidden. - /// - public bool IsHidden + + /// + /// Specifies whether button is hidden. + /// + public bool IsHidden { get { @@ -118,11 +117,11 @@ namespace TaskbarLib this.Update(); } } - - /// - /// Tooltip for button. - /// - public string Tooltip + + /// + /// Tooltip for button. + /// + public string Tooltip { get { @@ -136,24 +135,24 @@ namespace TaskbarLib this.Update(); } } - - internal uint Id + + internal uint Id { get { return this.id; } } - - internal IntPtr WindowHandle + + internal IntPtr WindowHandle { get { return this.windowHandle; } } - - protected SafeHandle IconHandle + + protected SafeHandle IconHandle { get { @@ -170,16 +169,16 @@ namespace TaskbarLib this.iconHandle = value; } } - - /// - /// Dispose current instance deterministicly. - /// - public void Dispose() - { - this.Dispose(true); - } - - internal void Initialize(IntPtr windowHandle) + + /// + /// Dispose current instance deterministicly. + /// + public void Dispose() + { + this.Dispose(true); + } + + internal void Initialize(IntPtr windowHandle) { if (this.id > 0) { @@ -201,54 +200,53 @@ namespace TaskbarLib this.id = id; } - - internal TaskbarClass.THUMBBUTTON GetUnmanagedButton() + + internal TaskbarNative.THUMBBUTTON GetUnmanagedButton() { - TaskbarClass.THUMBBUTTON button = new TaskbarClass.THUMBBUTTON(); + TaskbarNative.THUMBBUTTON button = new TaskbarNative.THUMBBUTTON(); button.iId = this.id; - button.dwMask = TaskbarClass.THBMASK.THB_FLAGS; - button.dwFlags = TaskbarClass.THBFLAGS.THBF_ENABLED; + button.dwMask = TaskbarNative.THBMask.FLAGS; + button.dwFlags = TaskbarNative.THBFlags.ENABLED; this.BeforeGetUnmanagedButton(ref button); if (this.IconHandle != null && !this.IconHandle.IsInvalid) { button.hIcon = this.iconHandle.DangerousGetHandle(); - - button.dwMask |= TaskbarClass.THBMASK.THB_ICON; + button.dwMask |= TaskbarNative.THBMask.ICON; } if (!string.IsNullOrEmpty(this.Tooltip)) { button.szTip = this.Tooltip; - button.dwMask |= TaskbarClass.THBMASK.THB_TOOLTIP; + button.dwMask |= TaskbarNative.THBMask.TOOLTIP; } if (this.IsDisabled) { - button.dwFlags |= TaskbarClass.THBFLAGS.THBF_DISABLED; + button.dwFlags |= TaskbarNative.THBFlags.DISABLED; } if (this.IsDismissedOnClick) { - button.dwFlags |= TaskbarClass.THBFLAGS.THBF_DISMISSONCLICK; + button.dwFlags |= TaskbarNative.THBFlags.DISMISSONCLICK; } if (!this.HasBackground) { - button.dwFlags |= TaskbarClass.THBFLAGS.THBF_NOBACKGROUND; + button.dwFlags |= TaskbarNative.THBFlags.NOBACKGROUND; } if (this.IsHidden) { - button.dwFlags |= TaskbarClass.THBFLAGS.THBF_HIDDEN; + button.dwFlags |= TaskbarNative.THBFlags.HIDDEN; } return button; } - - internal void FireClickEvent() + + internal void FireClickEvent() { var handler = this.Click; @@ -257,12 +255,12 @@ namespace TaskbarLib handler(this, EventArgs.Empty); } } - - internal virtual void BeforeGetUnmanagedButton(ref TaskbarClass.THUMBBUTTON button) + + internal virtual void BeforeGetUnmanagedButton(ref TaskbarNative.THUMBBUTTON button) { } - - protected virtual void Dispose(bool disposing) + + protected virtual void Dispose(bool disposing) { if (disposing) { @@ -274,7 +272,7 @@ namespace TaskbarLib this.iconHandle.Dispose(); } } - - protected abstract void Update(); - } + + protected abstract void Update(); + } \ No newline at end of file diff --git a/trunk/ProcessHacker/Forms/HackerWindow.cs b/trunk/ProcessHacker/Forms/HackerWindow.cs index c24c3401b..9faf8d199 100644 --- a/trunk/ProcessHacker/Forms/HackerWindow.cs +++ b/trunk/ProcessHacker/Forms/HackerWindow.cs @@ -45,7 +45,7 @@ namespace ProcessHacker { public delegate void LogUpdatedEventHandler(KeyValuePair? value); - private static Dictionary> thumbnailButtons; + private static Dictionary> thumbnailButtons; private delegate void AddMenuItemDelegate(string text, EventHandler onClick); @@ -2827,21 +2827,21 @@ namespace ProcessHacker #region "Taskbar ThumbnailButtons" - private TaskbarLib.ThumbnailBarButton CreateThumbnailBarImageButton(Bitmap Image, string imageName, string tooltip, bool isHidden, bool isDisabled, bool isDismissedOnClick, bool hasBackground) + private ThumbnailBarButton CreateThumbnailBarImageButton(Bitmap Image, string imageName, string tooltip, bool isHidden, bool isDisabled, bool isDismissedOnClick, bool hasBackground) { - return new TaskbarLib.ThumbnailBarButton(Image, tooltip, isHidden, isDisabled, isDismissedOnClick, hasBackground); + return new ThumbnailBarButton(Image, tooltip, isHidden, isDisabled, isDismissedOnClick, hasBackground); } - private static void AddThumbnailBarButtons(IntPtr windowHandle, IList buttons) + private static void AddThumbnailBarButtons(IntPtr windowHandle, IList buttons) { - var unmanagedButtons = new TaskbarLib.TaskbarClass.THUMBBUTTON[buttons.Count]; + var unmanagedButtons = new TaskbarNative.THUMBBUTTON[buttons.Count]; for (int i = 0; i < buttons.Count; i++) { buttons[i].Initialize(windowHandle); unmanagedButtons[i] = buttons[i].GetUnmanagedButton(); } - TaskbarLib.TaskbarClass.ThumbBarAddButtons(windowHandle, (uint)buttons.Count, unmanagedButtons); + TaskbarClass.ThumbBarAddButtons(windowHandle, (uint)buttons.Count, unmanagedButtons); if (!thumbnailButtons.ContainsKey(windowHandle)) { @@ -2851,7 +2851,7 @@ namespace ProcessHacker private void addTaskbarButtons() { - IList thumbnailBarButtons = new List() + IList thumbnailBarButtons = new List() { this.CreateThumbnailBarImageButton( ProcessHacker.Properties.Resources.ProcessHacker, @@ -2985,11 +2985,11 @@ namespace ProcessHacker break; case (int)WindowMessage.Command: - if (HiWord(m.WParam) == TaskbarLib.TaskbarClass.THUMBBUTTON.THBN_CLICKED) + if (HiWord(m.WParam) == TaskbarNative.THUMBBUTTON.THBN_CLICKED) { var buttonId = LoWord(m.WParam); - IList buttons; + IList buttons; if (thumbnailButtons.TryGetValue(m.HWnd, out buttons)) { foreach (var b in buttons) @@ -3457,7 +3457,7 @@ namespace ProcessHacker if (OSVersion.HasExtendedTaskbar) { - thumbnailButtons = new Dictionary>(); + thumbnailButtons = new Dictionary>(); this.addTaskbarButtons(); } } diff --git a/trunk/ProcessHacker/Forms/UpdaterDownloadWindow.cs b/trunk/ProcessHacker/Forms/UpdaterDownloadWindow.cs index f27d6ed3c..957efb023 100644 --- a/trunk/ProcessHacker/Forms/UpdaterDownloadWindow.cs +++ b/trunk/ProcessHacker/Forms/UpdaterDownloadWindow.cs @@ -76,7 +76,7 @@ namespace ProcessHacker private void UpdaterDownloadWindow_FormClosing(object sender, FormClosingEventArgs e) { - TaskbarLib.TaskbarClass.SetProgressState(TaskbarLib.TaskbarClass.TBPFlag.NOPROGRESS); + TaskbarClass.SetProgressState(TaskbarNative.TBPFlag.NOPROGRESS); } private void webClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) @@ -143,7 +143,7 @@ namespace ProcessHacker } } - TaskbarLib.TaskbarClass.SetProgressState(TaskbarLib.TaskbarClass.TBPFlag.NOPROGRESS); + TaskbarClass.SetProgressState(TaskbarNative.TBPFlag.NOPROGRESS); } private void webClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) @@ -156,8 +156,8 @@ namespace ProcessHacker progressDownload.Value = e.ProgressPercentage; - TaskbarLib.TaskbarClass.SetProgressState(TaskbarLib.TaskbarClass.TBPFlag.NORMAL); - TaskbarLib.TaskbarClass.SetProgressValue((ulong)e.BytesReceived, (ulong)e.TotalBytesToReceive); + TaskbarClass.SetProgressState(TaskbarNative.TBPFlag.NORMAL); + TaskbarClass.SetProgressValue((ulong)e.BytesReceived, (ulong)e.TotalBytesToReceive); } private void verifyWorker_DoWork(object sender, DoWorkEventArgs e) diff --git a/trunk/ProcessHacker/ProcessHacker.csproj b/trunk/ProcessHacker/ProcessHacker.csproj index 2ce6f0386..505d5447f 100644 --- a/trunk/ProcessHacker/ProcessHacker.csproj +++ b/trunk/ProcessHacker/ProcessHacker.csproj @@ -417,6 +417,7 @@ Component + diff --git a/trunk/ProcessHacker/UI/Icons/UsageIcon.cs b/trunk/ProcessHacker/UI/Icons/UsageIcon.cs index e435c8d23..049ff2075 100644 --- a/trunk/ProcessHacker/UI/Icons/UsageIcon.cs +++ b/trunk/ProcessHacker/UI/Icons/UsageIcon.cs @@ -40,7 +40,7 @@ namespace ProcessHacker _activeUsageIcon = value; if (_activeUsageIcon == null) - TaskbarLib.TaskbarClass.SetOverlayIcon(null, ""); + TaskbarClass.SetOverlayIcon(null, ""); } } @@ -111,7 +111,7 @@ namespace ProcessHacker _notifyIcon.Icon = value; if (this == _activeUsageIcon) - TaskbarLib.TaskbarClass.SetOverlayIcon(_notifyIcon.Icon, ""); + TaskbarClass.SetOverlayIcon(_notifyIcon.Icon, ""); } }