| 1 | using System;
 | 
|---|
| 2 | using System.Runtime.InteropServices;
 | 
|---|
| 3 | 
 | 
|---|
| 4 | public static class TaskBarProgress
 | 
|---|
| 5 | {
 | 
|---|
| 6 |     public enum TaskBarStates
 | 
|---|
| 7 |     {
 | 
|---|
| 8 |         NoProgress = 0,
 | 
|---|
| 9 |         Indeterminate = 0x1,
 | 
|---|
| 10 |         Normal = 0x2,
 | 
|---|
| 11 |         Error = 0x4,
 | 
|---|
| 12 |         Paused = 0x8
 | 
|---|
| 13 |     }
 | 
|---|
| 14 | 
 | 
|---|
| 15 |     [ComImport]
 | 
|---|
| 16 |     [Guid("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")]
 | 
|---|
| 17 |     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
 | 
|---|
| 18 |     private interface ITaskBarList3
 | 
|---|
| 19 |     {
 | 
|---|
| 20 |         // ITaskbarList
 | 
|---|
| 21 |         [PreserveSig]
 | 
|---|
| 22 |         void HrInit();
 | 
|---|
| 23 |         [PreserveSig]
 | 
|---|
| 24 |         void AddTab(IntPtr hwnd);
 | 
|---|
| 25 |         [PreserveSig]
 | 
|---|
| 26 |         void DeleteTab(IntPtr hwnd);
 | 
|---|
| 27 |         [PreserveSig]
 | 
|---|
| 28 |         void ActivateTab(IntPtr hwnd);
 | 
|---|
| 29 |         [PreserveSig]
 | 
|---|
| 30 |         void SetActiveAlt(IntPtr hwnd);
 | 
|---|
| 31 | 
 | 
|---|
| 32 |         // ITaskbarList2
 | 
|---|
| 33 |         [PreserveSig]
 | 
|---|
| 34 |         void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen);
 | 
|---|
| 35 | 
 | 
|---|
| 36 |         // ITaskbarList3
 | 
|---|
| 37 |         [PreserveSig]
 | 
|---|
| 38 |         void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal);
 | 
|---|
| 39 |         [PreserveSig]
 | 
|---|
| 40 |         void SetProgressState(IntPtr hwnd, TaskBarStates state);
 | 
|---|
| 41 |     }
 | 
|---|
| 42 | 
 | 
|---|
| 43 |     [ComImport]
 | 
|---|
| 44 |     [Guid("56fdf344-fd6d-11d0-958a-006097c9a090")]
 | 
|---|
| 45 |     [ClassInterface(ClassInterfaceType.None)]
 | 
|---|
| 46 |     private class CustomTaskBar
 | 
|---|
| 47 |     {
 | 
|---|
| 48 |     }
 | 
|---|
| 49 | 
 | 
|---|
| 50 |     private static readonly ITaskBarList3 TaskBarInstance = (ITaskBarList3)new CustomTaskBar();
 | 
|---|
| 51 |     private static readonly bool TaskBarSupported = Environment.OSVersion.Version >= new Version(6, 1);
 | 
|---|
| 52 | 
 | 
|---|
| 53 |     public static void SetState(IntPtr windowHandle, TaskBarStates taskBarState)
 | 
|---|
| 54 |     {
 | 
|---|
| 55 |         if (TaskBarSupported) TaskBarInstance.SetProgressState(windowHandle, taskBarState);
 | 
|---|
| 56 |     }
 | 
|---|
| 57 | 
 | 
|---|
| 58 |     public static void SetValue(IntPtr windowHandle, double progressValue, double progressMax)
 | 
|---|
| 59 |     {
 | 
|---|
| 60 |         if (TaskBarSupported) TaskBarInstance.SetProgressValue(windowHandle, (ulong)progressValue, (ulong)progressMax);
 | 
|---|
| 61 |     }
 | 
|---|
| 62 | }
 | 
|---|