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 (progressBar != null) { if (progressBar.State == TaskDialogProgressBarState.Marquee) { settings.NativeConfiguration.dwFlags |= TaskDialogNativeMethods.TASKDIALOG_FLAGS.TDF_SHOW_MARQUEE_PROGRESS_BAR; } else { settings.NativeConfiguration.dwFlags |= TaskDialogNativeMethods.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 |= TaskDialogNativeMethods.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 == TaskDialogNativeMethods.NO_DEFAULT_BUTTON_SPECIFIED) { settings.NativeConfiguration.dwFlags |= TaskDialogNativeMethods.TASKDIALOG_FLAGS.TDF_NO_DEFAULT_RADIO_BUTTON; } } }
// 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 (progressBar != null) { if (progressBar.State == TaskDialogProgressBarState.Marquee) { settings.NativeConfiguration.taskDialogFlags |= TaskDialogNativeMethods.TaskDialogOptions.ShowMarqueeProgressBar; } else { settings.NativeConfiguration.taskDialogFlags |= TaskDialogNativeMethods.TaskDialogOptions.ShowProgressBar; } } // 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.taskDialogFlags |= TaskDialogNativeMethods.TaskDialogOptions.UseCommandLinks; } // Set default button and add elevation icons // to appropriate buttons. settings.NativeConfiguration.defaultButtonIndex = 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.defaultRadioButtonIndex = defaultRadioButton; if (defaultRadioButton == TaskDialogNativeMethods.NoDefaultButtonSpecified) { settings.NativeConfiguration.taskDialogFlags |= TaskDialogNativeMethods.TaskDialogOptions.NoDefaultRadioButton; } } }
// Configuration is applied at dialog creation time. internal NativeTaskDialog(NativeTaskDialogSettings settings, TaskDialog outerDialog) { nativeDialogConfig = settings.NativeConfiguration; this.settings = settings; // Wireup dialog proc message loop for this instance. nativeDialogConfig.callback = new TaskDialogNativeMethods.TaskDialogCallback(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.UseElevationIcon) { if (settings.ElevatedButtons == null) { settings.ElevatedButtons = new List <int>(); } settings.ElevatedButtons.Add(control.Id); } } }
// Configuration is applied at dialog creation time. internal NativeTaskDialog( NativeTaskDialogSettings settings, TaskDialog outerDialog) { nativeDialogConfig = settings.NativeConfiguration; this.settings = settings; // Wireup dialog proc message loop for this instance. nativeDialogConfig.pfCallback = new TaskDialogNativeMethods.PFTASKDIALOGCALLBACK(DialogProc); // Keep a reference to the outer shell, so we can notify. this.outerDialog = outerDialog; }
private void ApplySupplementalSettings(NativeTaskDialogSettings settings) { if (progressBar != null) { if (progressBar.State != TaskDialogProgressBarState.Marquee) { settings.ProgressBarMinimum = progressBar.Minimum; settings.ProgressBarMaximum = progressBar.Maximum; settings.ProgressBarValue = progressBar.Value; settings.ProgressBarState = progressBar.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); footerCheckBoxChecked = nativeDialog.CheckBoxChecked; } finally { CleanUp(); nativeDialog = null; } return(result); }
// 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 (progressBar != null) { if (progressBar.State == TaskDialogProgressBarState.Marquee) settings.NativeConfiguration.dwFlags |= TaskDialogNativeMethods.TASKDIALOG_FLAGS.TDF_SHOW_MARQUEE_PROGRESS_BAR; else settings.NativeConfiguration.dwFlags |= TaskDialogNativeMethods.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 |= TaskDialogNativeMethods.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 == TaskDialogNativeMethods.NO_DEFAULT_BUTTON_SPECIFIED) settings.NativeConfiguration.dwFlags |= TaskDialogNativeMethods.TASKDIALOG_FLAGS.TDF_NO_DEFAULT_RADIO_BUTTON; } }
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 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); footerCheckBoxChecked = nativeDialog.CheckBoxChecked; } finally { CleanUp(); nativeDialog = null; } return result; }
private void ApplySupplementalSettings(NativeTaskDialogSettings settings) { if (progressBar != null) { if (progressBar.State != TaskDialogProgressBarState.Marquee) { settings.ProgressBarMinimum = progressBar.Minimum; settings.ProgressBarMaximum = progressBar.Maximum; settings.ProgressBarValue = progressBar.Value; settings.ProgressBarState = progressBar.State; } } if (HelpInvoked != null) settings.InvokeHelp = true; }
// 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 (progressBar != null) { if (progressBar.State == TaskDialogProgressBarState.Marquee) { settings.NativeConfiguration.taskDialogFlags |= TaskDialogNativeMethods.TaskDialogOptions.ShowMarqueeProgressBar; } else { settings.NativeConfiguration.taskDialogFlags |= TaskDialogNativeMethods.TaskDialogOptions.ShowProgressBar; } } // 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.taskDialogFlags |= TaskDialogNativeMethods.TaskDialogOptions.UseCommandLinks; } // Set default button and add elevation icons // to appropriate buttons. settings.NativeConfiguration.defaultButtonIndex = 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.defaultRadioButtonIndex = defaultRadioButton; if (defaultRadioButton == TaskDialogNativeMethods.NoDefaultButtonSpecified) { settings.NativeConfiguration.taskDialogFlags |= TaskDialogNativeMethods.TaskDialogOptions.NoDefaultRadioButton; } } }