Пример #1
0
        /// <summary>Frees the unmanages memory allocated by PreConfig().</summary>
        internal void PostConfig()
        {
            //Free allocated memory for custom buttons
            if (config.pButtons != IntPtr.Zero)
            {
                for (int i = 0; i < config.cButtons; ++i)
                {
                    unsafe
                    {
                        Marshal.DestroyStructure((IntPtr)((byte *)config.pButtons + i * CustomButton.SizeOf()), typeof(CustomButton));
                    }
                }
                Marshal.FreeHGlobal(config.pButtons);
            }

            //Free allocated memory for radio buttons
            if (config.pRadioButtons != IntPtr.Zero)
            {
                for (int i = 0; i < config.cRadioButtons; ++i)
                {
                    unsafe
                    {
                        Marshal.DestroyStructure((IntPtr)((byte *)config.pRadioButtons + i * CustomButton.SizeOf()), typeof(CustomButton));
                    }
                }
                Marshal.FreeHGlobal(config.pRadioButtons);
            }
        }
Пример #2
0
        /// <summary>Prepares the internal configuration structure.</summary>
        /// <remarks>Allocates some unmanaged memory, must always be followed by a PostConfig() call.</remarks>
        internal void PreConfig(IntPtr owner)
        {
            //Setup configuration structure
            config.hwndParent = owner;
            config.hInstance  = IntPtr.Zero; //will never use resources
            config.cbSize     = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(NativeMethods.TaskDialogConfig));

            //Icons
            config.hMainIcon = (IntPtr)CommonIcon;
            if (CustomIcon != null)
            {
                config.dwFlags  |= NativeMethods.TaskDialogFlags.TDF_USE_HICON_MAIN;
                config.hMainIcon = CustomIcon.Handle;
            }
            config.hFooterIcon = (IntPtr)FooterCommonIcon;
            if (FooterCustomIcon != null)
            {
                config.dwFlags    |= NativeMethods.TaskDialogFlags.TDF_USE_HICON_FOOTER;
                config.hFooterIcon = FooterCustomIcon.Handle;
            }

            //Data
            config.dwCommonButtons    = CommonButtons;
            config.pszWindowTitle     = Title;
            config.pszMainInstruction = Instruction;
            config.pszContent         = Content;

            config.pszVerificationText     = VerificationText;
            config.pszExpandedInformation  = ExpandedInformation;
            config.pszExpandedControlText  = ExpandedControlText;
            config.pszCollapsedControlText = CollapsedControlText;
            config.pszFooter = Footer;

            config.cxWidth = Width;

            //Special Buttons
            if (CustomButtons != null)
            {
                config.cButtons = (uint)CustomButtons.Length;
                config.pButtons = Marshal.AllocHGlobal(CustomButton.SizeOf() * CustomButtons.Length);

                for (int i = 0; i < CustomButtons.Length; ++i)
                {
                    unsafe
                    {
                        Marshal.StructureToPtr(CustomButtons[i], (IntPtr)((byte *)config.pButtons + i * CustomButton.SizeOf()), false);
                    }
                }
            }
            else
            {
                config.cButtons = 0;
                config.pButtons = IntPtr.Zero;
            }
            config.nDefaultButton = DefaultButton;

            //Radio Buttons
            if (RadioButtons != null)
            {
                config.cRadioButtons = (uint)RadioButtons.Length;
                config.pRadioButtons = Marshal.AllocHGlobal(CustomButton.SizeOf() * RadioButtons.Length);

                for (int i = 0; i < RadioButtons.Length; ++i)
                {
                    unsafe
                    {
                        Marshal.StructureToPtr(RadioButtons[i], (IntPtr)((byte *)config.pRadioButtons + i * CustomButton.SizeOf()), false);
                    }
                }
            }
            else
            {
                config.cRadioButtons = 0;
                config.pRadioButtons = IntPtr.Zero;
            }
            config.nDefaultRadioButton = EnabledRadioButton;

            //Callback
            config.pfCallback     = new NativeMethods.TaskDialogCallback(CommonCallbackProc);
            config.lpCallbackData = IntPtr.Zero;
        }