コード例 #1
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="taskDialog">The TaskDialog to show.</param>
        /// <exception cref="ArgumentNullException"><paramref name="taskDialog" /> is <c>null</c>.</exception>
        public NativeTaskDialogCommonDialog(NativeTaskDialog taskDialog)
        {
            if (taskDialog == null)
            {
                throw new ArgumentNullException("taskDialog");
            }

            _taskDialog = taskDialog;
        }
コード例 #2
0
        /// <summary>
        /// Create a TaskDialog from a TaskDialogConfig instance.
        /// </summary>
        /// <param name="taskConfig">A TaskDialogConfig instance that describes the TaskDialog.</param>
        /// <param name="button">The button that was clicked to close the TaskDialog.</param>
        /// <param name="radioButton">The radio button that was selected in the TaskDialog.</param>
        /// <param name="verificationFlagChecked">true if the verification checkbox was checked; false otherwise.</param>
        /// <returns></returns>
        public static int TaskDialogIndirect(TaskDialogConfig taskConfig, out int button, out int radioButton,
                                             out bool verificationFlagChecked)
        {
            ITaskDialog taskDialog;

            if (NativeTaskDialog.IsAvailableOnThisOs && !ForceEmulationMode)
            {
                taskDialog = new NativeTaskDialog();
            }
            else
            {
                taskDialog = new EmulatedTaskDialog(false);
            }

            return(taskDialog.TaskDialogIndirect(taskConfig, out button, out radioButton, out verificationFlagChecked));
        }
コード例 #3
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);
                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);
        }
コード例 #4
0
        // Analyzes the final state of the NativeTaskDialog instance and creates the
        // final TaskDialogResult that will be returned from the public API
        private TaskDialogResult ConstructDialogResult(NativeTaskDialog native)
        {
            Debug.Assert(native.ShowState == NativeDialogShowState.Closed, "dialog result being constructed for unshown dialog.");

            string customButton      = null;
            string radioButton       = null;
            bool   isCheckBoxChecked = false;
            TaskDialogButtonBase button;

            TaskDialogStandardButton standardButton = MapButtonIdToStandardButton(native.SelectedButtonID);

            // If returned ID isn't a standard button, let's fetch
            if (standardButton == TaskDialogStandardButton.None)
            {
                button = GetButtonForId(native.SelectedButtonID);
                if (button == null)
                {
                    throw new InvalidOperationException("Received bad control ID from Win32 callback.");
                }
                customButton = button.Name;
            }

            // If there were radio buttons and one was selected, figure out which one
            if (radioButtons.Count > 0 && native.SelectedRadioButtonID != SafeNativeMethods.NO_DEFAULT_BUTTON_SPECIFIED)
            {
                button = GetButtonForId(native.SelectedRadioButtonID);
                if (button == null)
                {
                    throw new InvalidOperationException("Received bad control ID from Win32 callback.");
                }
                radioButton = button.Name;
            }
            isCheckBoxChecked = native.CheckBoxChecked;

            return(new TaskDialogResult(
                       standardButton,
                       customButton,
                       radioButton,
                       isCheckBoxChecked));
        }
コード例 #5
0
        /// <exception cref="ArgumentException">Not supported yet.</exception>
        public static DialogResult ShowTaskDialogBox(IntPtr owner,
                                                     string title,
                                                     string mainInstruction,
                                                     string content,
                                                     string expandedInfo,
                                                     string footer,
                                                     string verificationText,
                                                     string radioButtons,
                                                     string commandButtons,
                                                     CommonButtons buttons,
                                                     CommonIcon mainIcon,
                                                     CommonIcon footerIcon,
                                                     int defaultIndex,
                                                     ProgressBarStyle progressBarStyle)
        {
            ITaskDialog taskDialog;

            if (NativeTaskDialog.IsAvailableOnThisOs && !ForceEmulationMode)
            {
                taskDialog = new NativeTaskDialog();
            }
            else
            {
                taskDialog = new EmulatedTaskDialog(false);
            }

            TaskConfig = new TaskDialogConfig();

            TaskConfig.Parent              = owner;
            TaskConfig.WindowTitle         = title;
            TaskConfig.MainInstruction     = mainInstruction;
            TaskConfig.Content             = content;
            TaskConfig.ExpandedInformation = expandedInfo;
            TaskConfig.Footer              = footer;

            // Radio Buttons
            if (!string.IsNullOrEmpty(radioButtons))
            {
                List <TaskDialogButton> lst = new List <TaskDialogButton>();
                string[] arr = radioButtons.Split(new[] { '|' });
                for (int i = 0; i < arr.Length; i++)
                {
                    try {
                        TaskDialogButton button = new TaskDialogButton {
                            ButtonId = 1000 + i, ButtonText = arr[i]
                        };
                        lst.Add(button);
                    } catch (FormatException) {}
                }
                TaskConfig.RadioButtons.AddRange(lst);
                TaskConfig.Flags.NoDefaultRadioButton = (defaultIndex == -1);
                if (defaultIndex >= 0)
                {
                    TaskConfig.DefaultRadioButton = defaultIndex + 1000;
                }
                else
                {
                    TaskConfig.DefaultRadioButton = 1000;
                }
            }

            // Custom Buttons
            if (!string.IsNullOrEmpty(commandButtons))
            {
                List <TaskDialogButton> lst = new List <TaskDialogButton>();
                string[] arr = commandButtons.Split(new[] { '|' });
                for (int i = 0; i < arr.Length; i++)
                {
                    try {
                        TaskDialogButton button = new TaskDialogButton {
                            ButtonId = 2000 + i, ButtonText = arr[i]
                        };
                        lst.Add(button);
                    } catch (FormatException) {}
                }
                TaskConfig.Buttons.AddRange(lst);
                if (defaultIndex >= 0)
                {
                    TaskConfig.DefaultButton = defaultIndex;
                }
            }

            TaskConfig.CommonButtons = buttons;
            TaskConfig.MainIcon      = mainIcon;
            if (TaskConfig.MainIcon == CommonIcon.Custom)
            {
                throw new ArgumentException("Not supported yet.", "mainIcon");
            }
            TaskConfig.FooterIcon = footerIcon;
            if (TaskConfig.FooterIcon == CommonIcon.Custom)
            {
                throw new ArgumentException("Not supported yet.", "footerIcon");
            }

            TaskConfig.Flags.EnableHyperLinks        = true;
            TaskConfig.Flags.ShowProgressBar         = (progressBarStyle == ProgressBarStyle.Continous) ? true : false;
            TaskConfig.Flags.ShowMarqueeProgressBar  = (progressBarStyle == ProgressBarStyle.Marquee) ? true : false;
            TaskConfig.Flags.AllowDialogCancellation = ((buttons & CommonButtons.Cancel) >= 0 ||
                                                        (buttons & CommonButtons.Close) >= 0);

            TaskConfig.Flags.CallbackTimer            = true;
            TaskConfig.Flags.ExpandedByDefault        = false;
            TaskConfig.Flags.ExpandFooterArea         = false;
            TaskConfig.Flags.PositionRelativeToWindow = true;
            TaskConfig.Flags.RtlLayout               = false;
            TaskConfig.Flags.CanBeMinimized          = false;
            TaskConfig.Flags.UseCommandLinks         = (TaskConfig.Buttons.Count > 0);
            TaskConfig.Flags.UseCommandLinksNoIcon   = false;
            TaskConfig.VerificationText              = verificationText;
            TaskConfig.Flags.VerificationFlagChecked = false;
            TaskConfig.ExpandedControlText           = "Hide details";
            TaskConfig.CollapsedControlText          = "Show details";

            taskDialog.Created             += TaskDialogCreated;
            taskDialog.ButtonClicked       += TaskDialogButtonClicked;
            taskDialog.HyperlinkClicked    += TaskDialogHyperlinkClicked;
            taskDialog.Timer               += TaskDialogTimer;
            taskDialog.Destroyed           += TaskDialogDestroyed;
            taskDialog.RadioButtonClicked  += TaskDialogRadioButtonClicked;
            taskDialog.DialogConstructed   += TaskDialogDialogConstructed;
            taskDialog.VerificationClicked += TaskDialogVerificationClicked;
            taskDialog.Help += TaskDialogHelp;
            taskDialog.ExpandoButtonClicked += TaskDialogExpandoButtonClicked;
            taskDialog.Navigated            += TaskDialogNavigated;

            DialogResult dialogResult = DialogResult.None;
            int          result       = taskDialog.TaskDialogIndirect(TaskConfig, out ButtonResult, out RadioButtonResult, out VerificationChecked);

            // Try to interpret the ButtonResult as a DialogResult
            try {
                if (ButtonResult < 1000)
                {
                    dialogResult = (DialogResult)ButtonResult;
                }
// ReSharper disable EmptyGeneralCatchClause
            } catch {}
// ReSharper restore EmptyGeneralCatchClause

            // if a command button was clicked, then change return result
            // to "DialogResult.OK" and set the CommandButtonResult)
            if (result >= 2000)
            {
                CommandButtonResult = result - 2000;
                dialogResult        = DialogResult.OK;
            }
            if (RadioButtonResult >= 1000)
            {
                // deduct the ButtonID start value for radio buttons
                RadioButtonResult -= 1000;
            }

            return(dialogResult);
        }
コード例 #6
0
ファイル: TaskDialog.cs プロジェクト: GodLesZ/svn-dump
		// Analyzes the final state of the NativeTaskDialog instance and creates the 
		// final TaskDialogResult that will be returned from the public API
		private static TaskDialogResult ConstructDialogResult(NativeTaskDialog native) {
			Debug.Assert(native.ShowState == DialogShowState.Closed, "dialog result being constructed for unshown dialog.");

			TaskDialogResult result = TaskDialogResult.Cancel;

			TaskDialogStandardButtons standardButton = MapButtonIdToStandardButton(native.SelectedButtonId);

			// If returned ID isn't a standard button, let's fetch 
			if (standardButton == TaskDialogStandardButtons.None) {
				result = TaskDialogResult.CustomButtonClicked;
			} else { result = (TaskDialogResult)standardButton; }

			return result;
		}
コード例 #7
0
ファイル: TaskDialog.cs プロジェクト: GodLesZ/svn-dump
		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;
		}
コード例 #8
0
ファイル: TaskDialog.cs プロジェクト: GodLesZ/svn-dump
		/// <summary>
		/// Dispose TaskDialog Resources
		/// </summary>
		/// <param name="disposing">If true, indicates that this is being called via Dispose rather than via the finalizer.</param>
		public void Dispose(bool disposing) {
			if (!disposed) {
				disposed = true;

				if (disposing) {
					// Clean up managed resources.
					if (nativeDialog != null && nativeDialog.ShowState == DialogShowState.Showing) {
						nativeDialog.NativeClose(TaskDialogResult.Cancel);
					}

					buttons = null;
					radioButtons = null;
					commandLinks = null;
				}

				// Clean up unmanaged resources SECOND, NTD counts on 
				// being closed before being disposed.
				if (nativeDialog != null) {
					nativeDialog.Dispose();
					nativeDialog = null;
				}

				if (staticDialog != null) {
					staticDialog.Dispose();
					staticDialog = null;
				}


			}
		}
コード例 #9
0
        private static TaskDialogResult ShowTaskDialog(TaskDialogOptions options)
        {
            var td = new NativeTaskDialog();

            td.WindowTitle         = options.Title;
            td.MainInstruction     = options.MainInstruction;
            td.Content             = options.Content;
            td.ExpandedInformation = options.ExpandedInfo;
            td.Footer = options.FooterText;

            bool hasCustomCancel = false;

            // Use of Command Links overrides any custom defined buttons
            if (options.CommandLinks != null && options.CommandLinks.Length > 0)
            {
                List <TaskDialogButton> lst = new List <TaskDialogButton>();
                for (int i = 0; i < options.CommandLinks.Length; i++)
                {
                    try
                    {
                        TaskDialogButton button = new TaskDialogButton();
                        button.ButtonId   = GetButtonIdForCommandButton(i);
                        button.ButtonText = options.CommandLinks[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                td.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0 &&
                    options.DefaultButtonIndex.Value < td.Buttons.Length)
                {
                    td.DefaultButton = td.Buttons[options.DefaultButtonIndex.Value].ButtonId;
                }
            }
            else if (options.CustomButtons != null && options.CustomButtons.Length > 0)
            {
                List <TaskDialogButton> lst = new List <TaskDialogButton>();
                for (int i = 0; i < options.CustomButtons.Length; i++)
                {
                    try
                    {
                        TaskDialogButton button = new TaskDialogButton();
                        button.ButtonId   = GetButtonIdForCustomButton(i);
                        button.ButtonText = options.CustomButtons[i];

                        if (!hasCustomCancel)
                        {
                            hasCustomCancel =
                                (button.ButtonText == TaskDialogOptions.LocalizedStrings.CommonButton_Close ||
                                 button.ButtonText == TaskDialogOptions.LocalizedStrings.CommonButton_Cancel);
                        }

                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }

                td.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex.Value >= 0 &&
                    options.DefaultButtonIndex.Value < td.Buttons.Length)
                {
                    td.DefaultButton = td.Buttons[options.DefaultButtonIndex.Value].ButtonId;
                }
                td.CommonButtons = TaskDialogCommonButtons.None;
            }

            if (options.RadioButtons != null && options.RadioButtons.Length > 0)
            {
                List <TaskDialogButton> lst = new List <TaskDialogButton>();
                for (int i = 0; i < options.RadioButtons.Length; i++)
                {
                    try
                    {
                        TaskDialogButton button = new TaskDialogButton();
                        button.ButtonId   = GetButtonIdForRadioButton(i);
                        button.ButtonText = options.RadioButtons[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                td.RadioButtons         = lst.ToArray();
                td.NoDefaultRadioButton = (!options.DefaultButtonIndex.HasValue || options.DefaultButtonIndex.Value == -1);
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0 &&
                    options.DefaultButtonIndex.Value < td.RadioButtons.Length)
                {
                    td.DefaultButton = td.RadioButtons[options.DefaultButtonIndex.Value].ButtonId;
                }
            }

            if (options.CommonButtons != TaskDialogCommonButtons.None)
            {
                td.CommonButtons = options.CommonButtons;

                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0)
                {
                    td.DefaultButton = GetButtonIdForCommonButton(options.CommonButtons, options.DefaultButtonIndex.Value);
                }
            }

            td.MainIcon                = options.MainIcon;
            td.CustomMainIcon          = options.CustomMainIcon;
            td.FooterIcon              = options.FooterIcon;
            td.CustomFooterIcon        = options.CustomFooterIcon;
            td.EnableHyperlinks        = DetectHyperlinks(options.Content, options.ExpandedInfo, options.FooterText);
            td.AllowDialogCancellation =
                (options.AllowDialogCancellation ||
                 hasCustomCancel ||
                 options.CommonButtons.HasFlag(TaskDialogCommonButtons.Close) ||
                 options.CommonButtons.HasFlag(TaskDialogCommonButtons.Cancel));
            td.CallbackTimer            = options.EnableCallbackTimer;
            td.ExpandedByDefault        = options.ExpandedByDefault;
            td.ExpandFooterArea         = options.ExpandToFooter;
            td.PositionRelativeToWindow = true;
            td.RightToLeftLayout        = false;
            td.NoDefaultRadioButton     = false;
            td.CanBeMinimized           = false;
            td.ShowProgressBar          = options.ShowProgressBar;
            td.ShowMarqueeProgressBar   = options.ShowMarqueeProgressBar;
            td.UseCommandLinks          = (options.CommandLinks != null && options.CommandLinks.Length > 0);
            td.UseCommandLinksNoIcon    = false;
            td.VerificationText         = options.VerificationText;
            td.VerificationFlagChecked  = options.VerificationByDefault;
            td.ExpandedControlText      = "Hide details";
            td.CollapsedControlText     = "Show details";
            td.Callback     = options.Callback;
            td.CallbackData = options.CallbackData;
            td.Config       = options;

            TaskDialogResult result;
            int diagResult = 0;
            TaskDialogSimpleResult simpResult = TaskDialogSimpleResult.None;
            bool verificationChecked          = false;
            int  radioButtonResult            = -1;
            int? commandButtonResult          = null;
            int? customButtonResult           = null;

            diagResult = td.Show(options.Owner, out verificationChecked, out radioButtonResult);

            if (radioButtonResult >= RadioButtonIDOffset)
            {
                simpResult         = (TaskDialogSimpleResult)diagResult;
                radioButtonResult -= RadioButtonIDOffset;
            }

            if (diagResult >= CommandButtonIDOffset)
            {
                simpResult          = TaskDialogSimpleResult.Command;
                commandButtonResult = diagResult - CommandButtonIDOffset;
            }
            else if (diagResult >= CustomButtonIDOffset)
            {
                simpResult         = TaskDialogSimpleResult.Custom;
                customButtonResult = diagResult - CustomButtonIDOffset;
            }
            else
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
            }

            result = new TaskDialogResult(
                simpResult,
                (String.IsNullOrEmpty(options.VerificationText) ? null : (bool?)verificationChecked),
                ((options.RadioButtons == null || options.RadioButtons.Length == 0) ? null : (int?)radioButtonResult),
                ((options.CommandLinks == null || options.CommandLinks.Length == 0) ? null : commandButtonResult),
                ((options.CustomButtons == null || options.CustomButtons.Length == 0) ? null : customButtonResult));

            return(result);
        }