Encapsulates the native logic required to create, configure, and show a TaskDialog, via the TaskDialogIndirect() Win32 function.
A new instance of this class should be created for each messagebox show, as the HWNDs for TaskDialogs do not remain constant across calls to TaskDialogIndirect.
Inheritance: IDisposable
Esempio n. 1
0
        /// <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;
                }
            }
        }
Esempio n. 2
0
        /// <summary>Constructs the dialog result.</summary>
        /// <param name="native">The native task dialog</param>
        /// <returns>The <c>TaskDialogResults</c>.</returns>
        static TaskDialogResult ConstructDialogResult(NativeTaskDialog native)
        {
            Debug.Assert(
                native.ShowState == DialogShowState.Closed, "dialog result being constructed for unshown dialog.");

            TaskDialogResult result;

            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);
        }
Esempio n. 3
0
        /// <summary>Shows the core dialog</summary>
        /// <returns>Returns the result of the <c>TaskDialog</c>.</returns>
        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.
                var 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);
        }