/// <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 API.WindowHandleWrapper(hwndOwner)) == DialogResult.OK); } API.IFileDialog dialog = null; try { dialog = new API.NativeFileOpenDialog(); SetDialogProperties(dialog); int result = dialog.Show(hwndOwner); if (result < 0) { if ((uint)result == (uint)API.HRESULT.ERROR_CANCELLED) { return(false); } else { throw System.Runtime.InteropServices.Marshal.GetExceptionForHR(result); } } GetResult(dialog); return(true); } finally { if (dialog != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(dialog); } } }
/// <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 API.WindowHandleWrapper(hwndOwner)) == DialogResult.OK; API.IFileDialog dialog = null; try { dialog = new API.NativeFileOpenDialog(); SetDialogProperties(dialog); int result = dialog.Show(hwndOwner); if( result < 0 ) { if( (uint)result == (uint)API.HRESULT.ERROR_CANCELLED ) return false; else throw System.Runtime.InteropServices.Marshal.GetExceptionForHR(result); } GetResult(dialog); return true; } finally { if( dialog != null ) System.Runtime.InteropServices.Marshal.FinalReleaseComObject(dialog); } }