Skip to content

Commit ba88233

Browse files
committed
implement the complete TaskbarList interface
1 parent a9fe23a commit ba88233

1 file changed

Lines changed: 103 additions & 25 deletions

File tree

FlashpointSecurePlayer/ProgressManager.cs

Lines changed: 103 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Drawing;
34
using System.Linq;
45
using System.Runtime.InteropServices;
56
using System.Text;
@@ -15,19 +16,49 @@ public static class ProgressManager {
1516
public static readonly IntPtr PBST_ERROR = (IntPtr)2;
1617
public static readonly IntPtr PBST_PAUSED = (IntPtr)3;
1718

18-
public enum TaskbarProgressBarState {
19-
NoProgress = 0,
20-
Indeterminate = 1,
21-
Normal = 2,
22-
Error = 4,
23-
Paused = 8
19+
public enum TBPF {
20+
TBPF_NOPROGRESS = 0x00000000,
21+
TBPF_INDETERMINATE = 0x00000001,
22+
TBPF_NORMAL = 0x00000002,
23+
TBPF_ERROR = 0x00000004,
24+
TBPF_PAUSED = 0x00000008
2425
}
2526

26-
[ComImport, Guid("56FDF344-FD6D-11D0-958A-006097C9A090"), ClassInterface(ClassInterfaceType.None)]
27-
private class ITaskbarList { }
27+
public enum TBATF {
28+
TBATF_USEMDITHUMBNAIL = 0x00000001,
29+
TBATF_USEMDILIVEPREVIEW = 0x00000002
30+
}
31+
32+
public enum THB : uint {
33+
THB_BITMAP = 0x00000001,
34+
THB_ICON = 0x00000002,
35+
THB_TOOLTIP = 0x00000004,
36+
THB_FLAGS = 0x00000008
37+
}
38+
39+
public enum THBF : uint {
40+
THBF_ENABLED = 0x00000000,
41+
THBF_DISABLED = 0x00000001,
42+
THBF_DISMISSONCLICK = 0x00000002,
43+
THBF_NOBACKGROUND = 0x00000004,
44+
THBF_HIDDEN = 0x00000008
45+
}
46+
47+
[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Auto)]
48+
public struct THUMBBUTTON {
49+
public THB dwMask;
50+
public uint iId;
51+
public uint iBitmap;
52+
public IntPtr hIcon;
53+
54+
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Shared.MAX_PATH)]
55+
public string szTip;
56+
57+
public THBF dwFlags;
58+
}
2859

2960
[ComImport, Guid("EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
30-
private interface ITaskbarList3 {
61+
public interface ITaskbarList3 {
3162
// ITaskbarList
3263
void HrInit();
3364
void AddTab(IntPtr hwnd);
@@ -45,10 +76,57 @@ bool fFullscreen
4576

4677
// ITaskbarList3
4778
void SetProgressValue(IntPtr hwnd, ulong ullCompleted, ulong ullTotal);
48-
void SetProgressState(IntPtr hwnd, TaskbarProgressBarState tbpFlags);
79+
void SetProgressState(IntPtr hwnd, TBPF tbpFlags);
80+
void RegisterTab(IntPtr hwndTab, IntPtr hwndMDI);
81+
void UnregisterTab(IntPtr hwndTab);
82+
void SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore);
83+
void SetTabActive(IntPtr hwndTab, IntPtr hwndMDI, TBATF tbatFlags);
84+
85+
void ThumbBarAddButtons(
86+
IntPtr hwnd,
87+
uint cButtons,
88+
89+
[MarshalAs(UnmanagedType.LPArray)]
90+
THUMBBUTTON[] pButtons
91+
);
92+
93+
void ThumbBarUpdateButtons(
94+
IntPtr hwnd,
95+
uint cButtons,
96+
97+
[MarshalAs(UnmanagedType.LPArray)]
98+
THUMBBUTTON[] pButtons
99+
);
100+
101+
void ThumbBarSetImageList(IntPtr hwnd, IntPtr himl);
102+
103+
void SetOverlayIcon(
104+
IntPtr hwnd,
105+
IntPtr hIcon,
106+
107+
[MarshalAs(UnmanagedType.LPWStr)]
108+
string pszDescription
109+
);
110+
111+
void SetThumbnailTooltip(
112+
IntPtr hwnd,
113+
114+
[MarshalAs(UnmanagedType.LPWStr)]
115+
string pszTip
116+
);
117+
118+
void SetThumbnailClip(
119+
IntPtr hwnd,
120+
121+
[MarshalAs(UnmanagedType.LPStruct)]
122+
Rectangle prcClip
123+
);
49124
}
50125

51-
private static readonly ITaskbarList3 taskbarList = (ITaskbarList3)new ITaskbarList();
126+
[ComImport, Guid("56FDF344-FD6D-11D0-958A-006097C9A090"), ClassInterface(ClassInterfaceType.None)]
127+
private class TaskbarList { }
128+
129+
private static readonly ITaskbarList3 taskbarList = (ITaskbarList3)new TaskbarList();
52130
private static readonly bool taskbarListSupported = Environment.OSVersion.Version >= new Version(6, 1);
53131
private static bool taskbarListInitialized = false;
54132

@@ -57,7 +135,7 @@ bool fFullscreen
57135
private static ProgressBar progressBar = null;
58136
private static Form progressForm = null;
59137
private static ulong progressFormValue = 0;
60-
private static TaskbarProgressBarState progressFormState = TaskbarProgressBarState.Normal;
138+
private static TBPF progressFormState = TBPF.TBPF_NORMAL;
61139
private static ProgressBarStyle style = ProgressBarStyle.Marquee;
62140
private static int value = 0;
63141
private static IntPtr state = PBST_NORMAL;
@@ -403,11 +481,11 @@ private static ProgressBarStyle ProgressFormStyle {
403481
}
404482

405483
// normal state does not take priority over indeterminate state
406-
if (ProgressManager.progressFormState != TaskbarProgressBarState.Normal) {
484+
if (ProgressManager.progressFormState != TBPF.TBPF_NORMAL) {
407485
return;
408486
}
409487

410-
ProgressManager.progressFormState = TaskbarProgressBarState.Indeterminate;
488+
ProgressManager.progressFormState = TBPF.TBPF_INDETERMINATE;
411489

412490
if (ProgressForm == null) {
413491
return;
@@ -443,14 +521,14 @@ private static int ProgressFormValue {
443521

444522
if (completed) {
445523
// if we have completed, ignore the value in the no progress state
446-
if (ProgressManager.progressFormState == TaskbarProgressBarState.NoProgress) {
524+
if (ProgressManager.progressFormState == TBPF.TBPF_NOPROGRESS) {
447525
return;
448526
}
449527

450-
ProgressManager.progressFormState = TaskbarProgressBarState.NoProgress;
528+
ProgressManager.progressFormState = TBPF.TBPF_NOPROGRESS;
451529
} else {
452530
// if we haven't completed, ignore the value in the indeterminate state
453-
if (ProgressManager.progressFormState == TaskbarProgressBarState.Indeterminate) {
531+
if (ProgressManager.progressFormState == TBPF.TBPF_INDETERMINATE) {
454532
return;
455533
}
456534
}
@@ -476,7 +554,7 @@ private static int ProgressFormValue {
476554
}
477555

478556
// if we previously completed, update the state
479-
if (ProgressManager.progressFormState == TaskbarProgressBarState.NoProgress) {
557+
if (ProgressManager.progressFormState == TBPF.TBPF_NOPROGRESS) {
480558
ProgressFormState = ProgressManager.state;
481559
}
482560
}
@@ -501,28 +579,28 @@ private static IntPtr ProgressFormState {
501579
}
502580

503581
if (value == PBST_ERROR) {
504-
if (ProgressManager.progressFormState == TaskbarProgressBarState.Error) {
582+
if (ProgressManager.progressFormState == TBPF.TBPF_ERROR) {
505583
return;
506584
}
507585

508-
ProgressManager.progressFormState = TaskbarProgressBarState.Error;
586+
ProgressManager.progressFormState = TBPF.TBPF_ERROR;
509587
} else if (value == PBST_PAUSED) {
510-
if (ProgressManager.progressFormState == TaskbarProgressBarState.Paused) {
588+
if (ProgressManager.progressFormState == TBPF.TBPF_PAUSED) {
511589
return;
512590
}
513591

514-
ProgressManager.progressFormState = TaskbarProgressBarState.Paused;
592+
ProgressManager.progressFormState = TBPF.TBPF_PAUSED;
515593
} else {
516-
if (ProgressManager.progressFormState == TaskbarProgressBarState.Normal) {
594+
if (ProgressManager.progressFormState == TBPF.TBPF_NORMAL) {
517595
return;
518596
}
519597

520598
// normal state does not take priority over indeterminate state
521-
if (ProgressManager.progressFormState == TaskbarProgressBarState.Indeterminate) {
599+
if (ProgressManager.progressFormState == TBPF.TBPF_INDETERMINATE) {
522600
return;
523601
}
524602

525-
ProgressManager.progressFormState = TaskbarProgressBarState.Normal;
603+
ProgressManager.progressFormState = TBPF.TBPF_NORMAL;
526604
}
527605

528606
if (ProgressForm == null) {

0 commit comments

Comments
 (0)