//------------------------------------------------------------------
//
// A P/Invoke wrapper for TaskDialog. Usability was given preference to perf and size.
//
//
//
//------------------------------------------------------------------
namespace ProcessHacker.Components
{
using System;
using System.Windows.Forms;
///
/// TaskDialog wrapped in a CommonDialog class. This is required to work well in
/// MMC 3.0. In MMC 3.0 you must use the ShowDialog methods on the MMC classes to
/// correctly show a modal dialog. This class will allow you to do this and keep access
/// to the results of the TaskDialog.
///
public class TaskDialogCommonDialog : CommonDialog
{
///
/// The TaskDialog we will display.
///
private TaskDialog taskDialog;
///
/// The result of the dialog, either a DialogResult value for common push buttons set in the TaskDialog.CommonButtons
/// member or the ButtonID from a TaskDialogButton structure set on the TaskDialog.Buttons member.
///
private int taskDialogResult;
///
/// The verification flag result of the dialog. True if the verification checkbox was checked when the dialog
/// was dismissed.
///
private bool verificationFlagCheckedResult;
///
/// TaskDialog wrapped in a CommonDialog class. THis is required to work well in
/// MMC 2.1. In MMC 2.1 you must use the ShowDialog methods on the MMC classes to
/// correctly show a modal dialog. This class will allow you to do this and keep access
/// to the results of the TaskDialog.
///
/// The TaskDialog to show.
public TaskDialogCommonDialog(TaskDialog taskDialog)
{
if (taskDialog == null)
{
throw new ArgumentNullException("taskDialog");
}
this.taskDialog = taskDialog;
}
///
/// The TaskDialog to show.
///
public TaskDialog TaskDialog
{
get { return this.taskDialog; }
}
///
/// The result of the dialog, either a DialogResult value for common push buttons set in the TaskDialog.CommonButtons
/// member or the ButtonID from a TaskDialogButton structure set on the TaskDialog.Buttons member.
///
public int TaskDialogResult
{
get { return this.taskDialogResult; }
}
///
/// The verification flag result of the dialog. True if the verification checkbox was checked when the dialog
/// was dismissed.
///
public bool VerificationFlagCheckedResult
{
get { return this.verificationFlagCheckedResult; }
}
///
/// Reset the common dialog.
///
public override void Reset()
{
this.taskDialog.Reset();
}
///
/// The required implementation of CommonDialog that shows the Task Dialog.
///
/// Owner window. This can be null.
/// If this method returns true, then ShowDialog will return DialogResult.OK.
/// If this method returns false, then ShowDialog will return DialogResult.Cancel. The
/// user of this class must use the TaskDialogResult member to get more information.
///
protected override bool RunDialog(IntPtr hwndOwner)
{
this.taskDialogResult = this.taskDialog.Show(hwndOwner, out this.verificationFlagCheckedResult);
return (this.taskDialogResult != (int)DialogResult.Cancel);
}
}
}