Esempio n. 1
0
        /// <summary>
        /// Display a task dialog.
        /// </summary>
        /// <param name="owner"></param>
        /// <returns></returns>
        public TaskDialogResult ShowDialog(IWin32Window owner)
        {
            int defaultButton;
            var win32Btns = ToButtons(this.Buttons, out defaultButton);

            int  hr, buttonId;
            bool verificationChecked;

            try
            {
                var config = new UnsafeNativeMethods.TASKDIALOGCONFIG();
                config.hwndParent              = GetOwnerWindow(owner);
                config.dwFlags                 = PropertiesToFlags();
                config.dwCommonButtons         = SanitiseFlags(this.commonButtons);
                config.pszWindowTitle          = this.windowTitle;
                config.pszMainIcon             = IconToID(this.mainIcon);
                config.pszMainInstruction      = this.mainInstruction;
                config.pszContent              = this.contentText;
                config.cButtons                = (uint)this.Buttons.Count;
                config.pButtons                = win32Btns;
                config.nDefaultButton          = defaultButton;
                config.pszVerificationText     = this.verificationText;
                config.pszExpandedInformation  = this.expandedInformation;
                config.pszExpandedControlText  = this.expandedControlText;
                config.pszCollapsedControlText = this.collapsedControlText;
                config.pszFooterIcon           = IconToID(this.footerIcon);
                config.pszFooter               = this.footerText;
                config.cxWidth                 = this.width >= 0 ? (uint)this.width : 0;

                hr = UnsafeNativeMethods.TaskDialogIndirect(config, out buttonId, IntPtr.Zero, out verificationChecked);
            }
            finally
            {
                Marshal.FreeCoTaskMem(win32Btns);
            }

            this.verificationChecked = false;
            if (hr >= 0)
            {
                this.verificationChecked = verificationChecked;
            }
            else
            {
                throw new COMException("TaskDialogIndirect() failed.", hr);
            }

            return(ResultFromKnownButtonID(buttonId));
        }
Esempio n. 2
0
        public void Show(IWin32Window parent, string caption, Exception e)
        {
            e = e.Unwrap();

            using (TraceSources.IapDesktop.TraceMethod().WithParameters(caption, e))
            {
                var details = new StringBuilder();
                for (var innerException = e.InnerException;
                     innerException != null; innerException =
                         innerException.InnerException)
                {
                    details.Append(e.InnerException.GetType().Name);
                    details.Append(":\n");
                    details.Append(innerException.Message);
                    details.Append("\n");
                }

                TraceSources.IapDesktop.TraceError($"Exception: {details}");

                var config = new UnsafeNativeMethods.TASKDIALOGCONFIG()
                {
                    cbSize                 = (uint)Marshal.SizeOf(typeof(UnsafeNativeMethods.TASKDIALOGCONFIG)),
                    hwndParent             = parent.Handle,
                    dwFlags                = 0,
                    dwCommonButtons        = UnsafeNativeMethods.TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_OK_BUTTON,
                    pszWindowTitle         = "An error occured",
                    MainIcon               = UnsafeNativeMethods.TD_ERROR_ICON,
                    pszMainInstruction     = caption,
                    pszContent             = e.Message,
                    pszExpandedInformation = details.ToString()
                };

                UnsafeNativeMethods.TaskDialogIndirect(
                    ref config,
                    out int buttonPressed,
                    out int radioButtonPressed,
                    out bool verificationFlagPressed);
            }
        }