-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskbarProgress.cs
111 lines (101 loc) · 2.54 KB
/
TaskbarProgress.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Runtime.InteropServices;
namespace Planetoid_DB
{
/// <summary>
///
/// </summary>
public static class TaskbarProgress
{
/// <summary>
///
/// </summary>
public enum TaskbarStates
{
/// <summary>
///
/// </summary>
NoProgress = 0,
/// <summary>
///
/// </summary>
Indeterminate = 0x1,
/// <summary>
///
/// </summary>
Normal = 0x2,
/// <summary>
///
/// </summary>
Error = 0x4,
/// <summary>
///
/// </summary>
Paused = 0x8
}
/// <summary>
///
/// </summary>
[ComImport()]
[Guid("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")]
[InterfaceType(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, ulong ullCompleted, ulong ullTotal);
[PreserveSig]
void SetProgressState(IntPtr hwnd, TaskbarStates state);
}
/// <summary>
///
/// </summary>
[Guid("56FDF344-FD6D-11d0-958A-006097C9A090")]
[ClassInterface(ClassInterfaceType.None)]
[ComImport()]
private class TaskbarInstance
{
}
private static readonly ITaskbarList3 taskbarInstance = (ITaskbarList3)new TaskbarInstance();
private static readonly bool taskbarSupported = Environment.OSVersion.Version >= new Version(major: 6, minor: 1);
/// <summary>
///
/// </summary>
/// <param name="windowHandle"></param>
/// <param name="taskbarState"></param>
public static void SetState(IntPtr windowHandle, TaskbarStates taskbarState)
{
if (taskbarSupported)
{
taskbarInstance.SetProgressState(hwnd: windowHandle, state: taskbarState);
}
}
/// <summary>
///
/// </summary>
/// <param name="windowHandle"></param>
/// <param name="progressValue"></param>
/// <param name="progressMax"></param>
public static void SetValue(IntPtr windowHandle, double progressValue, double progressMax)
{
if (taskbarSupported)
{
taskbarInstance.SetProgressValue(hwnd: windowHandle, ullCompleted: (ulong)progressValue, ullTotal: (ulong)progressMax);
}
}
}
}