protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _Enabled = true;
     }
     _NativeButton = new NativeMethods.TASKDIALOG_BUTTON();
     base.Dispose(disposing);
 }
Пример #2
0
        private IUICommand ShowTaskDialog()
        {
            NativeMethods.TASKDIALOGCONFIG tdc = new NativeMethods.TASKDIALOGCONFIG();
            tdc.cbSize             = Marshal.SizeOf(tdc);
            tdc.hwndParent         = NativeMethods.GetForegroundWindow();
            tdc.pszWindowTitle     = " ";
            tdc.pszMainInstruction = Title;
            tdc.dwFlags            = NativeMethods.TASKDIALOG_FLAGS.SIZE_TO_CONTENT;
            tdc.pszContent         = Content;
            if (Commands.Count == 0)
            {
                tdc.dwCommonButtons = NativeMethods.TASKDIALOG_COMMON_BUTTON_FLAGS.CLOSE_BUTTON;
            }
            else
            {
                if (CancelCommandIndex != uint.MaxValue)
                {
                    tdc.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.ALLOW_DIALOG_CANCELLATION;
                }
            }

            IntPtr bptr = Marshal.AllocHGlobal(Commands.Count * 8);

            for (int ibut = 0; ibut < Commands.Count; ibut++)
            {
                var but = new NativeMethods.TASKDIALOG_BUTTON {
                    nButtonID = ibut + 11, pszButtonText = Commands[ibut].Label
                };
                Marshal.StructureToPtr(but, IntPtr.Add(bptr, ibut * 8), false);
            }

            if (DefaultCommandIndex != uint.MaxValue)
            {
                tdc.nDefaultButton = DefaultCommandIndex + 11;
            }

            tdc.pButtons = bptr;
            tdc.cButtons = Commands.Count;
            int ibtn;
            int hresult = NativeMethods.TaskDialogIndirect(ref tdc, out ibtn, IntPtr.Zero, IntPtr.Zero);

            Marshal.FreeHGlobal(bptr);

            if (ibtn > 10)
            {
                return(Commands[ibtn - 11]);
            }
            if (ibtn == 2 && CancelCommandIndex != uint.MaxValue)
            {
                return(Commands[(int)CancelCommandIndex]);
            }

            return(null);
        }
Пример #3
0
        private IUICommand ShowTaskDialog()
        {
            NativeMethods.TASKDIALOGCONFIG tdc = new NativeMethods.TASKDIALOGCONFIG();
            tdc.cbSize = Marshal.SizeOf(tdc);
            tdc.hwndParent = NativeMethods.GetForegroundWindow();
            tdc.pszWindowTitle = " ";
            tdc.pszMainInstruction = Title;
            tdc.dwFlags = NativeMethods.TASKDIALOG_FLAGS.SIZE_TO_CONTENT;
            tdc.pszContent = Content;
            if (this.Commands.Count == 0)
            {
                tdc.dwCommonButtons = NativeMethods.TASKDIALOG_COMMON_BUTTON_FLAGS.CLOSE_BUTTON;
            }
            else
            {
                if (CancelCommandIndex != uint.MaxValue)
                {
                    tdc.dwFlags |= NativeMethods.TASKDIALOG_FLAGS.ALLOW_DIALOG_CANCELLATION;
                }
            }

            IntPtr bptr = Marshal.AllocHGlobal(Commands.Count * 8);
            for(int ibut = 0; ibut < Commands.Count; ibut++)
            {
                var but = new NativeMethods.TASKDIALOG_BUTTON { nButtonID = ibut+11, pszButtonText = Commands[ibut].Label };
                Marshal.StructureToPtr(but, IntPtr.Add(bptr, ibut * 8), false);
            }

            if (DefaultCommandIndex != uint.MaxValue)
            {
                tdc.nDefaultButton = DefaultCommandIndex + 11;
            }

            tdc.pButtons = bptr;
            tdc.cButtons = Commands.Count;
            int ibtn;
            int hresult = NativeMethods.TaskDialogIndirect(ref tdc, out ibtn, IntPtr.Zero, IntPtr.Zero);
            Marshal.FreeHGlobal(bptr);

            if(ibtn > 10)
            {
                return Commands[ibtn - 11];
            }
            if(ibtn == 2 && CancelCommandIndex != uint.MaxValue)
            {
                return Commands[(int)CancelCommandIndex];
            }

            return null;
        }
Пример #4
0
        private NativeMethods.TASKDIALOG_BUTTON[] BuildButtonStructArray(List <TaskDialogButtonBase> controls)
        {
            NativeMethods.TASKDIALOG_BUTTON[] buttonStructs;
            TaskDialogButtonBase button;

            int totalButtons = controls.Count;

            buttonStructs = new NativeMethods.TASKDIALOG_BUTTON[totalButtons];
            for (int i = 0; i < totalButtons; i++)
            {
                button           = controls[i];
                buttonStructs[i] = new NativeMethods.TASKDIALOG_BUTTON(button.Id, button.ToString());
            }
            return(buttonStructs);
        }
 /// <summary>
 /// Initializes a new instance of radio button
 /// </summary>
 public TaskDialogRadioButton() : base()
 {
     _NativeButton = new NativeMethods.TASKDIALOG_BUTTON();
     _Enabled      = true;
 }