in Python/Product/VSCommon/Infrastructure/TaskDialog.cs [156:295]
public TaskDialogButton ShowModal() {
var config = new NativeMethods.TASKDIALOGCONFIG();
config.cbSize = (uint)Marshal.SizeOf(typeof(NativeMethods.TASKDIALOGCONFIG));
config.pButtons = IntPtr.Zero;
config.pRadioButtons = IntPtr.Zero;
var uiShell = (IVsUIShell)_provider.GetService(typeof(SVsUIShell));
if (uiShell == null) {
// We are shutting down, so return the default
return SelectedButton;
}
uiShell.GetDialogOwnerHwnd(out config.hwndParent);
uiShell.EnableModeless(0);
var customButtons = new List<TaskDialogButton>();
config.dwCommonButtons = 0;
foreach (var button in Buttons) {
var flag = GetButtonFlag(button);
if (flag != 0) {
config.dwCommonButtons |= flag;
} else {
customButtons.Add(button);
}
}
try {
if (customButtons.Any()) {
config.cButtons = (uint)customButtons.Count;
var ptr = config.pButtons = Marshal.AllocHGlobal(customButtons.Count * Marshal.SizeOf(typeof(NativeMethods.TASKDIALOG_BUTTON)));
for (int i = 0; i < customButtons.Count; ++i) {
NativeMethods.TASKDIALOG_BUTTON data;
data.nButtonID = GetButtonId(null, null, i);
if (string.IsNullOrEmpty(customButtons[i].Subtext)) {
data.pszButtonText = customButtons[i].Text;
} else {
data.pszButtonText = string.Format("{0}\n{1}", customButtons[i].Text, customButtons[i].Subtext);
}
Marshal.StructureToPtr(data, ptr + i * Marshal.SizeOf(typeof(NativeMethods.TASKDIALOG_BUTTON)), false);
}
} else {
config.cButtons = 0;
config.pButtons = IntPtr.Zero;
}
if (_buttons.Any() && SelectedButton != null) {
config.nDefaultButton = GetButtonId(SelectedButton, customButtons);
} else {
config.nDefaultButton = 0;
}
if (_radioButtons.Any()) {
config.cRadioButtons = (uint)_radioButtons.Count;
var ptr = config.pRadioButtons = Marshal.AllocHGlobal(_radioButtons.Count * Marshal.SizeOf(typeof(NativeMethods.TASKDIALOG_BUTTON)));
for (int i = 0; i < _radioButtons.Count; ++i) {
NativeMethods.TASKDIALOG_BUTTON data;
data.nButtonID = GetRadioId(null, null, i);
data.pszButtonText = _radioButtons[i].Text;
Marshal.StructureToPtr(data, ptr + i * Marshal.SizeOf(typeof(NativeMethods.TASKDIALOG_BUTTON)), false);
}
if (SelectedRadioButton != null) {
config.nDefaultRadioButton = GetRadioId(SelectedRadioButton, _radioButtons);
} else {
config.nDefaultRadioButton = 0;
}
}
config.pszWindowTitle = Title;
config.pszMainInstruction = MainInstruction;
config.pszContent = Content;
config.pszExpandedInformation = ExpandedInformation;
config.pszExpandedControlText = ExpandedControlText;
config.pszCollapsedControlText = CollapsedControlText;
config.pszFooter = Footer;
config.pszVerificationText = VerificationText;
config.pfCallback = Callback;
config.MainIcon.hMainIcon = (int)GetIconResource(MainIcon);
config.FooterIcon.hMainIcon = (int)GetIconResource(FooterIcon);
if (Width.HasValue && Width.Value != 0) {
config.cxWidth = (uint)Width.Value;
} else {
config.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.TDF_SIZE_TO_CONTENT;
}
if (EnableHyperlinks) {
config.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.TDF_ENABLE_HYPERLINKS;
}
if (AllowCancellation) {
config.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.TDF_ALLOW_DIALOG_CANCELLATION;
}
if (UseCommandLinks && config.cButtons > 0) {
config.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.TDF_USE_COMMAND_LINKS;
}
if (!ShowExpandedInformationInContent) {
config.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.TDF_EXPAND_FOOTER_AREA;
}
if (ExpandedByDefault) {
config.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.TDF_EXPANDED_BY_DEFAULT;
}
if (SelectedVerified) {
config.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.TDF_VERIFICATION_FLAG_CHECKED;
}
if (CanMinimize) {
config.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.TDF_CAN_BE_MINIMIZED;
}
config.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.TDF_POSITION_RELATIVE_TO_WINDOW;
int selectedButton, selectedRadioButton;
bool verified;
ErrorHandler.ThrowOnFailure((int)NativeMethods.TaskDialogIndirect(
config,
out selectedButton,
out selectedRadioButton,
out verified
));
SelectedButton = GetButton(selectedButton, customButtons);
SelectedRadioButton = GetRadio(selectedRadioButton, _radioButtons);
SelectedVerified = verified;
} finally {
uiShell.EnableModeless(1);
if (config.pButtons != IntPtr.Zero) {
for (int i = 0; i < customButtons.Count; ++i) {
Marshal.DestroyStructure(config.pButtons + i * Marshal.SizeOf(typeof(NativeMethods.TASKDIALOG_BUTTON)), typeof(NativeMethods.TASKDIALOG_BUTTON));
}
Marshal.FreeHGlobal(config.pButtons);
}
if (config.pRadioButtons != IntPtr.Zero) {
for (int i = 0; i < _radioButtons.Count; ++i) {
Marshal.DestroyStructure(config.pRadioButtons + i * Marshal.SizeOf(typeof(NativeMethods.TASKDIALOG_BUTTON)), typeof(NativeMethods.TASKDIALOG_BUTTON));
}
Marshal.FreeHGlobal(config.pRadioButtons);
}
}
return SelectedButton;
}