using System.Runtime.InteropServices; using System; using ProcessHacker.Native.Api; namespace TaskbarLib { 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, TaskbarProgressFlags 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, TabActiveFlags 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, int 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, int 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, TabFlags stpFlags); #endregion } [Flags] public enum TabActiveFlags { UseMdiThumbnail = 0x1, UseMdiLivePreview = 0x2 } [Flags] public enum TaskbarProgressFlags { NoProgress = 0x0, Indeterminate = 0x1, Normal = 0x2, Error = 0x4, Paused = 0x8 } [Flags] public enum TabFlags { None = 0x0, UseAppThumbnailAlways = 0x1, UseAppThumbnailWhenActive = 0x2, UseAppPeekAlways = 0x4, UseAppPeekWhenActive = 0x8, } [Flags] public enum ThumbButtonMask { Bitmap = 0x1, Icon = 0x2, Tooltip = 0x4, Flags = 0x8 } [Flags] public enum ThumbButtonFlags : int { Enabled = 0x00000000, Disabled = 0x00000001, DismissOnClick = 0x00000002, NoBackground = 0x00000004, Hidden = 0x00000008, NonInteractive = 0x00000010 } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct ThumbButton { //WPARAM value for a THUMBBUTTON being clicked. internal const int Clicked = 0x1800; [MarshalAs(UnmanagedType.U4)] public ThumbButtonMask Mask; public int Id; public int BitmapIndex; public IntPtr IconHandle; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 259)] public string TooltipText; public ThumbButtonFlags Flags; } } }