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
|
[Flags]
public enum TaskDialogButtons
{
None = 0x0,
OK = 0x1,
Yes = 0x2,
No = 0x4,
Cancel = 0x8,
Retry = 0x10,
Close = 0x20
}
public enum TaskDialogIcon
{
None = 0x0,
Warning = 0xFFFF,
Error = 0xFFFE,
Information = 0xFFFD,
Shield = 0xFFFC,
}
public enum TaskDialogResult
{
None = 0x0,
OK = 0x1,
Cancel = 0x2,
Retry = 0x4,
Yes = 0x6,
No = 0x7,
Close = 0x8
}
public class TaskDialog
{
[DllImport("comctl32.dll", CharSet = CharSet.Unicode, EntryPoint = "TaskDialog")]
private static extern int ShowTaskDialog(IntPtr hWndParent, IntPtr hInstance, string pszWindowTitle, string pszMainInstruction, string pszContent, int dwCommonButtons, IntPtr pszIcon, out int pnButton);
public string Title { get; set; }
public string Instruction { get; set; }
public string Content { get; set; }
public TaskDialogButtons Buttons { get; set; }
public TaskDialogIcon Icon { get; set; }
public IntPtr Parent { get; set; }
public static TaskDialogResult Show(string content)
{
return Show(string.Empty, string.Empty, content);
}
public static TaskDialogResult Show(string title, string instruction, string content)
{
return Show(title, instruction, content, TaskDialogButtons.OK);
}
public static TaskDialogResult Show(string title, string instruction, string content, TaskDialogButtons buttons)
{
return Show(title, instruction, content, buttons, TaskDialogIcon.None);
}
public static TaskDialogResult Show(string title, string instruction, string content, TaskDialogButtons buttons, TaskDialogIcon icon)
{
return Show(title, instruction, content, buttons, icon);
}
public static TaskDialogResult Show(string title, string instruction, string content, TaskDialogButtons buttons, TaskDialogIcon icon, IntPtr parent)
{
int result;
ShowTaskDialog(parent, IntPtr.Zero, title, instruction, content, (int)buttons, new IntPtr((int)icon), out result);
return (TaskDialogResult)result;
}
public TaskDialogResult Show()
{
return Show(Title, Instruction, Content, Buttons, Icon, Parent);
}
}
|