示例#1
0
        public unsafe void TASKDIALOGCONFIG_x64_ensure_layout()
        {
            if (!Environment.Is64BitProcess)
            {
                return;
            }

            TASKDIALOGCONFIG sut  = new TASKDIALOGCONFIG();
            byte *           addr = (byte *)&sut;

            Assert.Equal(0, (byte *)&sut.cbSize - addr);                    // 4, UINT
            Assert.Equal(4, (byte *)&sut.hwndParent - addr);                // 8, HWND
            Assert.Equal(12, (byte *)&sut.hInstance - addr);                // 8, HINSTANCE
            Assert.Equal(20, (byte *)&sut.dwFlags - addr);                  // 4, TASKDIALOG_FLAGS
            Assert.Equal(24, (byte *)&sut.dwCommonButtons - addr);          // 4, TASKDIALOG_COMMON_BUTTON_FLAGS
            Assert.Equal(28, (byte *)&sut.pszWindowTitle - addr);           // 8, PCWSTR
            Assert.Equal(36, (byte *)&sut.mainIcon - addr);                 // 8, union { HICON; PCWSTR; }
            Assert.Equal(44, (byte *)&sut.pszMainInstruction - addr);       // 8, PCWSTR
            Assert.Equal(52, (byte *)&sut.pszContent - addr);               // 8, PCWSTR
            Assert.Equal(60, (byte *)&sut.cButtons - addr);                 // 4, UINT
            Assert.Equal(64, (byte *)&sut.pButtons - addr);                 // 8, const TASKDIALOG_BUTTON *
            Assert.Equal(72, (byte *)&sut.nDefaultButton - addr);           // 4, int
            Assert.Equal(76, (byte *)&sut.cRadioButtons - addr);            // 4, UINT
            Assert.Equal(80, (byte *)&sut.pRadioButtons - addr);            // 8, const TASKDIALOG_BUTTON *
            Assert.Equal(88, (byte *)&sut.nDefaultRadioButton - addr);      // 4, int
            Assert.Equal(92, (byte *)&sut.pszVerificationText - addr);      // 8, PCWSTR
            Assert.Equal(100, (byte *)&sut.pszExpandedInformation - addr);  // 8, PCWSTR
            Assert.Equal(108, (byte *)&sut.pszExpandedControlText - addr);  // 8, PCWSTR
            Assert.Equal(116, (byte *)&sut.pszCollapsedControlText - addr); // 8, PCWSTR
            Assert.Equal(124, (byte *)&sut.footerIcon - addr);              // 8, union { HICON; PCWSTR; }
            Assert.Equal(132, (byte *)&sut.pszFooter - addr);               // 8, PCWSTR
            Assert.Equal(140, (byte *)&sut.pfCallback - addr);              // 8, PFTASKDIALOGCALLBACK
            Assert.Equal(148, (byte *)&sut.lpCallbackData - addr);          // 8, LONG_PTR
            Assert.Equal(156, (byte *)&sut.cxWidth - addr);                 // 4, UINT
        }
 private static bool TaskDialogIndirect(ref TASKDIALOGCONFIG pTaskConfig, out int pnButton, System.IntPtr pnRadioButton, System.IntPtr pfVerificationFlagChecked, out int phr)
 {
     try
     {
         phr = TaskDialogIndirect(ref pTaskConfig, out pnButton, pnRadioButton, pfVerificationFlagChecked);
     }
     catch (System.EntryPointNotFoundException)
     {
         pnButton = default(int);
         phr      = default(int);
         return(false);
     }
     return(true);
 }
示例#3
0
        public virtual DialogResult Show(IntPtr hwnd)
        {
            var config = new TASKDIALOGCONFIG();

            config.cbSize                  = Marshal.SizeOf(config);
            config.hwndParent              = hwnd;
            config.dwFlags                 = Flags;
            config.dwCommonButtons         = CommonButtonFlags;
            config.pszWindowTitle          = Title;
            config.pszMainInstruction      = MainInstruction;
            config.pszContent              = Content;
            config.pszVerificationText     = VerificationText;
            config.pszExpandedControlText  = ExpandedInformation;
            config.pszCollapsedControlText = CollapsedControlText;
            config.pszFooter               = Footer;
            if (MainIcon != IntPtr.Zero)
            {
                config.hMainIcon = MainIcon;
                //config.dwFlags |= TASKDIALOG_FLAGS.TDF_USE_HICON_MAIN;
            }

            if (FooterIcon != IntPtr.Zero)
            {
                config.hFooterIcon = FooterIcon;
                //config.dwFlags |= TASKDIALOG_FLAGS.TDF_USE_HICON_FOOTER;
            }

            config.cxWidth = Width;
            try
            {
                TaskDialogIndirect(ref config, out int button, out int radioButton, out bool verificationFlagChecked).ThrowOnError();
                ResultButton                  = button;
                ResultRadioButton             = radioButton;
                ResultVerificationFlagChecked = verificationFlagChecked;
                return((DialogResult)button);
            }
            catch (EntryPointNotFoundException ex)
            {
                MessageBox.Show(hwnd, ex.GetInterestingExceptionMessage() + Environment.NewLine + Environment.NewLine + "Make sure the application's main executable has a manifest that enables visual styles.", "Task Dialog Fatal Error", icon: MessageBoxIcon.Stop);
                return(DialogResult.Abort);
            }
            catch (Exception e)
            {
                MessageBox.Show(hwnd, e.GetInterestingExceptionMessage(), "Task Dialog Fatal Error", icon: MessageBoxIcon.Stop);
                return(DialogResult.Abort);
            }
        }
        public static System.Windows.Forms.DialogResult Show(string Content, string Title, System.Windows.Forms.MessageBoxButtons Buttons, System.Windows.Forms.MessageBoxIcon Icon, TASKDIALOG_COMMON_BUTTON_FLAGS CommonButtons, System.IntPtr MainIcon, System.Windows.Forms.IWin32Window Window = null)
        {
            TASKDIALOGCONFIG TaskConfig = new TASKDIALOGCONFIG();

            TaskConfig.cbSize                  = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(TASKDIALOGCONFIG));
            TaskConfig.hwndParent              = (Window != null) ? Window.Handle : System.IntPtr.Zero;
            TaskConfig.hInstance               = System.IntPtr.Zero;
            TaskConfig.dwFlags                 = TASKDIALOG_FLAGS.TDF_SIZE_TO_CONTENT;
            TaskConfig.dwCommonButtons         = CommonButtons;
            TaskConfig.pszWindowTitle          = Title;
            TaskConfig.hMainIcon               = MainIcon;
            TaskConfig.pszMainInstruction      = null;
            TaskConfig.pszContent              = Content;
            TaskConfig.cButtons                = 0;
            TaskConfig.nDefaultButton          = 0;
            TaskConfig.cRadioButtons           = 0;
            TaskConfig.pszVerificationText     = null;
            TaskConfig.pszExpandedInformation  = null;
            TaskConfig.pszExpandedControlText  = null;
            TaskConfig.pszCollapsedControlText = null;
            TaskConfig.hFooterIcon             = System.IntPtr.Zero;
            TaskConfig.pszFooter               = null;
            TaskConfig.pfCallback              = null;
            TaskConfig.cxWidth                 = 0;
            int iButton;
            int hr;

            if (TaskDialogIndirect(ref TaskConfig, out iButton, System.IntPtr.Zero, System.IntPtr.Zero, out hr))
            {
                if (hr == 0)
                {
                    return((System.Windows.Forms.DialogResult)iButton);
                }
                else
                {
                    System.Diagnostics.Trace.Assert(false);
                }
            }
            return(System.Windows.Forms.MessageBox.Show(Window, Content, Title, Buttons, Icon));
        }
 internal static extern void TaskDialogIndirect(
     [In] ref TASKDIALOGCONFIG pTaskConfig,
     [Out] out int pnButton,
     [Out] out int pnRadioButton,
     [Out] out bool pfVerificationFlagChecked);
示例#6
0
 public static extern void TaskDialogIndirect([In] ref TASKDIALOGCONFIG pTaskConfig, out int pnButton, out int pnRadioButton, [MarshalAs(UnmanagedType.Bool)] out bool pfVerificationFlagChecked);
示例#7
0
 public static extern HRESULT TaskDialogIndirect(
     [In] TASKDIALOGCONFIG pTaskConfig,
     [Out] out int pnButton,
     [Out] out int pnRadioButton,
     [MarshalAs(UnmanagedType.Bool)][Out] out bool pVerificationFlagChecked);
示例#8
0
 internal static extern int TaskDialogIndirect(
     ref TASKDIALOGCONFIG pTaskConfig,
     out int pnButton,
     out int pnRadioButton,
     [MarshalAs(UnmanagedType.Bool)] out bool pfverificationFlagChecked);
示例#9
0
 private static extern HRESULT TaskDialogIndirect(ref TASKDIALOGCONFIG pTaskConfig, out int pnButton, out int pnRadioButton, out bool pfVerificationFlagChecked);
 private static extern int TaskDialogIndirect([System.Runtime.InteropServices.In] ref TASKDIALOGCONFIG pTaskConfig, [System.Runtime.InteropServices.Out] out int pnButton, System.IntPtr pnRadioButton, System.IntPtr pfVerificationFlagChecked);
示例#11
0
 internal static extern int TaskDialogIndirect(ref TASKDIALOGCONFIG pTaskConfig, out int pnButton, IntPtr pnRadioButton, IntPtr pfVerificationFlagChecked);
        /// <summary>
        ///     <see cref="TASKDIALOGCONFIG" />を作成します。
        /// </summary>
        /// <param name="parentWindowHandle">親ウィンドウのハンドル。</param>
        /// <returns>作成した<see cref="TASKDIALOGCONFIG" />。</returns>
        private TASKDIALOGCONFIG CreateConfig(IntPtr parentWindowHandle)
        {
            var result = TASKDIALOGCONFIG.Create();

            result.hwndParent      = parentWindowHandle;
            result.flags           = this.Flags;
            result.commonButtons   = this.CommonButtons;
            result.windowTitle     = this.WindowTitle;
            result.mainIcon        = new TASKDIALOGCONFIG_ICON((int)this.MainIcon);
            result.mainInstruction = this.InstructionText;
            result.content         = this.ContentText;

            result.verificationText     = this.VerificationText;
            result.expandedInformation  = this.ExpandedText;
            result.expandedControlText  = this.ExpandedControlText;
            result.collapsedControlText = this.CollapsedControlText;

            result.footerIcon = new TASKDIALOGCONFIG_ICON((int)this.FooterIcon);
            result.footerText = this.FooterText;

            result.callback = this.DialogProc;

            // Buttons
            if (this.CustomButtons != null)
            {
                result.buttonCount        = (uint)this.CustomButtons.Count;
                result.buttons            = this.CustomButtons.Handle;
                result.defaultButtonIndex = FindDefaultButtonId(this.CustomButtons);
            }
            else if (this.CommandLinks != null)
            {
                result.buttonCount        = (uint)this.CommandLinks.Count;
                result.buttons            = this.CommandLinks.Handle;
                result.flags             |= TASKDIALOG_FLAGS.TDF_USE_COMMAND_LINKS;
                result.defaultButtonIndex = FindDefaultButtonId(this.CommandLinks);
            }

            // Radio Buttons
            if (this.RadioButtons != null)
            {
                result.radioButtonCount        = (uint)this.RadioButtons.Count;
                result.radioButtons            = this.RadioButtons.Handle;
                result.defaultRadioButtonIndex = FindDefaultButtonId(this.RadioButtons);
                if (result.defaultRadioButtonIndex == TaskDialogNativeMethods.NoDefaultButtonSpecified)
                {
                    result.flags |= TASKDIALOG_FLAGS.TDF_NO_DEFAULT_RADIO_BUTTON;
                }
            }

            // Progress Bar
            if (this.ProgressBar is TaskDialogProgressBar)
            {
                result.flags |= TASKDIALOG_FLAGS.TDF_SHOW_PROGRESS_BAR;
            }
            else if (this.ProgressBar is TaskDialogMarquee)
            {
                result.flags |= TASKDIALOG_FLAGS.TDF_SHOW_MARQUEE_PROGRESS_BAR;
            }

            return(result);
        }
示例#13
0
 internal static extern int TaskDialogIndirect(ref TASKDIALOGCONFIG pTaskConfig, out int pnButton, IntPtr pnRadioButton, IntPtr pfVerificationFlagChecked);
        internal static int ShowOptionsTaskDialog(
            IWin32Window parent,
            string windowTitle,
            string mainInstruction,
            string content,
            string details,
            IList <string> optionCaptions,
            string verificationText,
            out bool verificationFlagPressed)
        {
            // The options to show.
            var options = optionCaptions
                          .Select(caption => Marshal.StringToHGlobalUni(caption))
                          .ToArray();

            // Wrap each option by a TASKDIALOG_BUTTON_RAW structure and
            // marshal them one by one into a native memory buffer.
            var buttonsBuffer = Marshal.AllocHGlobal(
                Marshal.SizeOf <TASKDIALOG_BUTTON_RAW>() * options.Length);

            var currentButton = buttonsBuffer;

            for (int i = 0; i < options.Length; i++)
            {
                Marshal.StructureToPtr <TASKDIALOG_BUTTON_RAW>(
                    new TASKDIALOG_BUTTON_RAW()
                {
                    nButtonID     = i,
                    pszButtonText = options[i]
                },
                    currentButton,
                    false);
                currentButton += Marshal.SizeOf <TASKDIALOG_BUTTON_RAW>();
            }

            try
            {
                var config = new TASKDIALOGCONFIG()
                {
                    cbSize          = (uint)Marshal.SizeOf(typeof(TASKDIALOGCONFIG)),
                    hwndParent      = parent.Handle,
                    dwFlags         = TASKDIALOG_FLAGS.TDF_USE_COMMAND_LINKS,
                    dwCommonButtons = TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_OK_BUTTON |
                                      TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_CANCEL_BUTTON,
                    pszWindowTitle         = windowTitle,
                    MainIcon               = TD_SHIELD_ICON_INFO_BACKGROUND,
                    pszMainInstruction     = mainInstruction,
                    pszContent             = content,
                    pButtons               = buttonsBuffer,
                    cButtons               = (uint)options.Length,
                    pszExpandedInformation = details,
                    pszVerificationText    = verificationText
                };

                TaskDialogIndirect(
                    ref config,
                    out int buttonPressed,
                    out int radioButtonPressed,
                    out verificationFlagPressed);

                return(buttonPressed);
            }
            finally
            {
                foreach (var option in options)
                {
                    Marshal.FreeHGlobal(option);
                }

                Marshal.FreeHGlobal(buttonsBuffer);
            }
        }
示例#15
0
 public static extern Int32 TaskDialogIndirect(
     [In] TASKDIALOGCONFIG pTaskConfig,
     [Out, Optional] out Int32 pnButton,
     [Out, Optional] out Int32 pnRadioButton,
     [Out, Optional, MarshalAs(UnmanagedType.Bool)] out Boolean pfVerificationFlagChecked);