Beispiel #1
0
 /// <summary>
 /// Specifies a common dialog box.
 /// </summary>
 /// <param name="hwndOwner">A value that represents the window handle of the owner window for the common dialog box.</param>
 /// <returns><see langword="true"/> if the file could be opened; otherwise, <see langword="false"/>.</returns>
 protected override bool RunDialog(IntPtr hwndOwner)
 {
     if (DownlevelDialog != null)
     {
         return(DownlevelDialog.ShowDialog(hwndOwner == IntPtr.Zero ? null : new Interop.WindowHandleWrapper(hwndOwner)) == DialogResult.OK);
     }
     else
     {
         return(RunFileDialog(hwndOwner));
     }
 }
        /// <summary>
        /// Displays the file dialog.
        /// </summary>
        /// <param name="owner">Handle to the window that owns the dialog.</param>
        /// <returns>If the user clicks the OK button of the dialog that is displayed (e.g. <see cref="VistaOpenFileDialog" />, <see cref="VistaSaveFileDialog" />), <see langword="true" /> is returned; otherwise, <see langword="false" />.</returns>
        public bool?ShowDialog(Window owner)
        {
            _owner = owner;
            if (DownlevelDialog != null)
            {
                return(DownlevelDialog.ShowDialog(owner));
            }
            else
            {
                IntPtr ownerHandle = owner == null?NativeMethods.GetActiveWindow() : new WindowInteropHelper(owner).Handle;

                return(ShowDialog(ownerHandle));
            }
        }
        /// <summary>
        ///  When overridden in a derived class, displays a particular type of common dialog box.
        /// </summary>
        protected override bool RunDialog(IntPtr hwndOwner)
        {
            Window owner = (Window)HwndSource.FromHwnd(hwndOwner).RootVisual;

            _owner = owner;
            if (DownlevelDialog != null)
            {
                return(DownlevelDialog.ShowDialog(owner) ?? false);
            }

            Ookii.Dialogs.Wpf.Interop.IFileDialog dialog = null;
            try
            {
                dialog = CreateFileDialog();
                SetDialogProperties(dialog);
                int result = dialog.Show(hwndOwner);
                if (result < 0)
                {
                    if (result == (int)HRESULT.ERROR_CANCELLED)
                    {
                        return(false);
                    }
                    else
                    {
                        throw System.Runtime.InteropServices.Marshal.GetExceptionForHR(result);
                    }
                }
                return(true);
            }
            finally
            {
                if (dialog != null)
                {
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(dialog);
                }
            }
        }