[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);
}
}