using System; using System.Runtime.InteropServices; public static class TaskBarProgress { public enum TaskBarStates { NoProgress = 0, Indeterminate = 0x1, Normal = 0x2, Error = 0x4, Paused = 0x8 } [ComImport] [Guid("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] private 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 [PreserveSig] void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal); [PreserveSig] void SetProgressState(IntPtr hwnd, TaskBarStates state); } [ComImport] [Guid("56fdf344-fd6d-11d0-958a-006097c9a090")] [ClassInterface(ClassInterfaceType.None)] private class CustomTaskBar { } private static readonly ITaskBarList3 TaskBarInstance = (ITaskBarList3)new CustomTaskBar(); private static readonly bool TaskBarSupported = Environment.OSVersion.Version >= new Version(6, 1); public static void SetState(IntPtr windowHandle, TaskBarStates taskBarState) { if (TaskBarSupported) TaskBarInstance.SetProgressState(windowHandle, taskBarState); } public static void SetValue(IntPtr windowHandle, double progressValue, double progressMax) { if (TaskBarSupported) TaskBarInstance.SetProgressValue(windowHandle, (ulong)progressValue, (ulong)progressMax); } }