private void ApplyCoreSettings(NativeTaskDialogSettings settings) { ApplyGeneralNativeConfiguration(settings.NativeConfiguration); ApplyTextConfiguration(settings.NativeConfiguration); ApplyOptionConfiguration(settings.NativeConfiguration); ApplyControlConfiguration(settings); }
// Builds the actual configuration // that the NativeTaskDialog (and underlying Win32 API) // expects, by parsing the various control // lists, marshalling to the unmanaged heap, etc. private void ApplyControlConfiguration(NativeTaskDialogSettings settings) { // Deal with progress bars/marquees. if (marquee != null) { settings.NativeConfiguration.dwFlags |= SafeNativeMethods.TASKDIALOG_FLAGS.TDF_SHOW_MARQUEE_PROGRESS_BAR; } else if (progressBar != null) { settings.NativeConfiguration.dwFlags |= SafeNativeMethods.TASKDIALOG_FLAGS.TDF_SHOW_PROGRESS_BAR; } // Build the native struct arrays that NativeTaskDialog // needs - though NTD will handle // the heavy lifting marshalling to make sure // all the cleanup is centralized there. if (buttons.Count > 0 || commandLinks.Count > 0) { // These are the actual arrays/lists of // the structs that we'll copy to the // unmanaged heap. List <TaskDialogButtonBase> sourceList = ( buttons.Count > 0 ? buttons : commandLinks); settings.Buttons = BuildButtonStructArray(sourceList); // Apply option flag that forces all // custom buttons to render as command links. if (commandLinks.Count > 0) { settings.NativeConfiguration.dwFlags |= SafeNativeMethods.TASKDIALOG_FLAGS.TDF_USE_COMMAND_LINKS; } // Set default button and add elevation icons // to appropriate buttons. settings.NativeConfiguration.nDefaultButton = FindDefaultButtonId(sourceList); ApplyElevatedIcons(settings, sourceList); } if (radioButtons.Count > 0) { settings.RadioButtons = BuildButtonStructArray(radioButtons); // Set default radio button - radio buttons don't support. int defaultRadioButton = FindDefaultButtonId(radioButtons); settings.NativeConfiguration.nDefaultRadioButton = defaultRadioButton; if (defaultRadioButton == SafeNativeMethods.NO_DEFAULT_BUTTON_SPECIFIED) { settings.NativeConfiguration.dwFlags |= SafeNativeMethods.TASKDIALOG_FLAGS.TDF_NO_DEFAULT_RADIO_BUTTON; } } }
/// <summary>Initializes a new instance of the <see cref="NativeTaskDialog" /> class.</summary> /// <param name="settings">The settings.</param> /// <param name="outerDialog">The outer dialog.</param> internal NativeTaskDialog(NativeTaskDialogSettings settings, TaskDialog outerDialog) { nativeDialogConfig = settings.NativeConfiguration; this.settings = settings; // Wireup dialog proc message loop for this instance. nativeDialogConfig.Callback = DialogProc; ShowState = DialogShowState.PreShow; // Keep a reference to the outer shell, so we can notify. this.outerDialog = outerDialog; }
private static void ApplyElevatedIcons(NativeTaskDialogSettings settings, List <TaskDialogButtonBase> controls) { foreach (TaskDialogButton control in controls) { if (control.ShowElevationIcon) { if (settings.ElevatedButtons == null) { settings.ElevatedButtons = new List <int>(); } settings.ElevatedButtons.Add(control.Id); } } }
private void ApplySupplementalSettings(NativeTaskDialogSettings settings) { if (progressBar != null) { settings.ProgressBarMinimum = progressBar.Minimum; settings.ProgressBarMaximum = progressBar.Maximum; settings.ProgressBarState = progressBar.State; settings.ProgressBarValue = progressBar.Value; } else if (marquee != null) { settings.ProgressBarState = marquee.State; } if (HelpInvoked != null) { settings.InvokeHelp = true; } }
private TaskDialogResult ShowCore() { TaskDialogResult result; try { // Populate control lists, based on current // contents - note we are somewhat late-bound // on our control lists, to support XAML scenarios. SortDialogControls(); // First, let's make sure it even makes // sense to try a show. ValidateCurrentDialogSettings(); // Create settings object for new dialog, // based on current state. NativeTaskDialogSettings settings = new NativeTaskDialogSettings(); ApplyCoreSettings(settings); ApplySupplementalSettings(settings); // Show the dialog. // NOTE: this is a BLOCKING call; the dialog proc callbacks // will be executed by the same thread as the // Show() call before the thread of execution // contines to the end of this method. nativeDialog = new NativeTaskDialog(settings, this); nativeDialog.NativeShow(); // Build and return dialog result to public API - leaving it // null after an exception is thrown is fine in this case result = ConstructDialogResult(nativeDialog); checkBoxChecked = result.CheckBoxChecked; } finally { CleanUp(); nativeDialog = null; } return(result); }