-
Notifications
You must be signed in to change notification settings - Fork 0
/
TaskbarProgressHelper.cs
80 lines (63 loc) · 2.11 KB
/
TaskbarProgressHelper.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
using System;
using System.Runtime.InteropServices;
namespace bookGrabber {
internal static class TaskbarProgressHelper {
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 {
[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);
}
[ComImport]
[Guid("56fdf344-fd6d-11d0-958a-006097c9a090")]
[ClassInterface(ClassInterfaceType.None)]
private class TaskbarInstance {
}
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
private static readonly ITaskbarList3 taskbarInstance = (ITaskbarList3) new TaskbarInstance();
private static readonly bool taskbarSupported = Environment.OSVersion.Version >= new Version(6, 1);
private static IntPtr handle = IntPtr.Zero;
private static IntPtr Handle {
get {
if (handle == IntPtr.Zero) {
//handle = Process.GetCurrentProcess().MainWindowHandle;
handle = GetConsoleWindow();
}
return handle;
}
}
public static void SetState(TaskbarStates taskbarState) {
if (taskbarSupported)
taskbarInstance.SetProgressState(Handle, taskbarState);
}
public static void SetValue(double progressValue, double progressMax) {
if (taskbarSupported)
taskbarInstance.SetProgressValue(Handle, (ulong) progressValue, (ulong) progressMax);
}
}
}