using System; using System.Runtime.InteropServices; namespace Windows7Taskbar { #region Interop ITaskbarList3 internal enum TBPFLAG { TBPF_NOPROGRESS = 0, TBPF_INDETERMINATE = 0x1, TBPF_NORMAL = 0x2, TBPF_ERROR = 0x4, TBPF_PAUSED = 0x8 } internal enum TBATFLAG { TBATF_USEMDITHUMBNAIL = 0x1, TBATF_USEMDILIVEPREVIEW = 0x2 } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] internal struct THUMBBUTTON { [MarshalAs(UnmanagedType.U4)] public THBMASK dwMask; public uint iId; public uint iBitmap; public IntPtr hIcon; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string szTip; [MarshalAs(UnmanagedType.U4)] public THBFLAGS dwFlags; } [StructLayout(LayoutKind.Sequential)] internal struct RECT { public int left; public int top; public int right; public int bottom; public RECT(int left, int top, int right, int bottom) { this.left = left; this.top = top; this.right = right; this.bottom = bottom; } } internal enum THBMASK { THB_BITMAP = 0x1, THB_ICON = 0x2, THB_TOOLTIP = 0x4, THB_FLAGS = 0x8 } internal enum THBFLAGS { THBF_ENABLED = 0, THBF_DISABLED = 0x1, THBF_DISMISSONCLICK = 0x2, THBF_NOBACKGROUND = 0x4, THBF_HIDDEN = 0x8 } [ComImportAttribute()] [GuidAttribute("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")] [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] internal interface ITaskbarList3 { // ITaskbarList [PreserveSig] void HrInit(); [PreserveSig] void AddTab(IntPtr hwnd); [PreserveSig] void DeleteTab(IntPtr hwnd); [PreserveSig] void ActivateTab(IntPtr hwnd); [PreserveSig] void SetActiveAlt(IntPtr hwnd); // ITaskbarList2 [PreserveSig] void MarkFullscreenWindow( IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen); // ITaskbarList3 void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal); void SetProgressState(IntPtr hwnd, TBPFLAG tbpFlags); void RegisterTab(IntPtr hwndTab, IntPtr hwndMDI); void UnregisterTab(IntPtr hwndTab); void SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore); void SetTabActive(IntPtr hwndTab, IntPtr hwndMDI, TBATFLAG tbatFlags); void ThumbBarAddButtons( IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray)] THUMBBUTTON[] pButtons); void ThumbBarUpdateButtons( IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray)] THUMBBUTTON[] pButtons); void ThumbBarSetImageList(IntPtr hwnd, IntPtr himl); void SetOverlayIcon( IntPtr hwnd, IntPtr hIcon, [MarshalAs(UnmanagedType.LPWStr)] string pszDescription); void SetThumbnailTooltip( IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszTip); void SetThumbnailClip( IntPtr hwnd, /*[MarshalAs(UnmanagedType.LPStruct)]*/ ref RECT prcClip); } [GuidAttribute("56FDF344-FD6D-11d0-958A-006097C9A090")] [ClassInterfaceAttribute(ClassInterfaceType.None)] [ComImportAttribute()] internal class CTaskbarList { } #endregion public static class Windows7Taskbar { #region Infrastructure private static ITaskbarList3 _taskbarList; internal static ITaskbarList3 TaskbarList { get { if (_taskbarList == null) { lock (typeof(Windows7Taskbar)) { if (_taskbarList == null) { _taskbarList = (ITaskbarList3)new CTaskbarList(); _taskbarList.HrInit(); } } } return _taskbarList; } } #endregion #region Taskbar Progress Bar /// /// Represents the thumbnail progress bar state. /// public enum ThumbnailProgressState { /// /// No progress is displayed. /// NoProgress = 0, /// /// The progress is indeterminate (marquee). /// Indeterminate = 0x1, /// /// Normal progress is displayed. /// Normal = 0x2, /// /// An error occurred (red). /// Error = 0x4, /// /// The operation is paused (yellow). /// Paused = 0x8 } /// /// Sets the progress state of the specified window's /// taskbar button. /// /// The window handle. /// The progress state. public static void SetProgressState(IntPtr hwnd, ThumbnailProgressState state) { TaskbarList.SetProgressState(hwnd, (TBPFLAG)state); } /// /// Sets the progress value of the specified window's /// taskbar button. /// /// The window handle. /// The current value. /// The maximum value. public static void SetProgressValue(IntPtr hwnd, ulong current, ulong maximum) { TaskbarList.SetProgressValue(hwnd, current, maximum); } #endregion } }