Example #1
0
        // 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 NativeMethods.PFTASKDIALOGCALLBACK(DialogProc);

            // Keep a reference to the outer shell, so we can notify
            this.outerDialog = outerDialog;
        }
Example #2
0
        // 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 NativeMethods.PFTASKDIALOGCALLBACK(DialogProc);

            // Keep a reference to the outer shell, so we can notify
            this.outerDialog = outerDialog;
        }
Example #3
0
 // Builds the actual configuration that the NativeTaskDialog (and underlying Win32 API)
 // expects, by parsing the various control lists, marshalling to the unmgd heap, etc.
 private void MarshalDialogControlStructs(NativeTaskDialogSettings settings)
 {
     if (settings.Buttons != null && settings.Buttons.Length > 0)
     {
         buttonArray = AllocateAndMarshalButtons(settings.Buttons);
         settings.NativeConfiguration.pButtons = buttonArray;
         settings.NativeConfiguration.cButtons = (uint)settings.Buttons.Length;
     }
     if (settings.RadioButtons != null && settings.RadioButtons.Length > 0)
     {
         radioButtonArray = AllocateAndMarshalButtons(settings.RadioButtons);
         settings.NativeConfiguration.pRadioButtons = radioButtonArray;
         settings.NativeConfiguration.cRadioButtons = (uint)settings.RadioButtons.Length;
     }
 }
Example #4
0
        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;
        }
Example #5
0
 private 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);
         }
     }
 }
Example #6
0
        // Builds the actual configuration that the NativeTaskDialog (and underlying Win32 API)
        // expects, by parsing the various control lists, marshalling to the unmgd heap, etc.
        private void ApplyControlConfiguration(NativeTaskDialogSettings settings)
        {
            // Deal with progress bars/marquees
            if (marquee != null)
                settings.NativeConfiguration.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.TDF_SHOW_MARQUEE_PROGRESS_BAR;
            else if (progressBar != null)
                settings.NativeConfiguration.dwFlags |= NativeMethods.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 |= NativeMethods.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 == NativeMethods.NO_DEFAULT_BUTTON_SPECIFIED)
                    settings.NativeConfiguration.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.TDF_NO_DEFAULT_RADIO_BUTTON;
            }
        }
Example #7
0
 private void ApplyCoreSettings(NativeTaskDialogSettings settings)
 {
     ApplyGeneralNativeConfiguration(settings.NativeConfiguration);
     ApplyTextConfiguration(settings.NativeConfiguration);
     ApplyOptionConfiguration(settings.NativeConfiguration);
     ApplyControlConfiguration(settings);
 }
Example #8
0
        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);
                isShowing = true;
                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);
            }
            finally
            {
                isShowing = false;
                CleanUp();
                nativeDialog = null;
            }

            return result;
        }
Example #9
0
 // Builds the actual configuration that the NativeTaskDialog (and underlying Win32 API)
 // expects, by parsing the various control lists, marshalling to the unmgd heap, etc.
 private void MarshalDialogControlStructs(NativeTaskDialogSettings settings)
 {
     if (settings.Buttons != null && settings.Buttons.Length > 0)
     {
         buttonArray = AllocateAndMarshalButtons(settings.Buttons);
         settings.NativeConfiguration.pButtons = buttonArray;
         settings.NativeConfiguration.cButtons = (uint)settings.Buttons.Length;
     }
     if (settings.RadioButtons != null && settings.RadioButtons.Length > 0)
     {
         radioButtonArray = AllocateAndMarshalButtons(settings.RadioButtons);
         settings.NativeConfiguration.pRadioButtons = radioButtonArray;
         settings.NativeConfiguration.cRadioButtons = (uint)settings.RadioButtons.Length;
     }
 }