예제 #1
0
        private bool RunDialog(IntPtr owner)
        {
            IFileDialog dialog = null;

            try
            {
                dialog = new NativeFileOpenDialog();
                SetDialogProperties(dialog);
                int result = dialog.Show(owner);
                if (result < 0)
                {
                    if ((uint)result == (uint)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);
                }
            }
        }
예제 #2
0
        public DialogResult ShowDialog()
        {
            int result = _dialog.Show(GetActiveWindow());

            if (result < 0)
            {
                if ((uint)result == (uint)HRESULT.E_CANCELLED)
                {
                    return(DialogResult.Cancel);
                }
                throw Marshal.GetExceptionForHR(result);
            }

            IShellItem dialogResult;

            _dialog.GetResult(out dialogResult);
            dialogResult.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out _fileName);

            IFileDialogCustomize customize = (IFileDialogCustomize)_dialog;

            customize.GetCheckButtonState(RunManualCheckboxId, out _runManualMode);
            model.PreferenceSettings.OpenFileInManualExecutionMode = _runManualMode;

            return(DialogResult.OK);
        }
예제 #3
0
        public static string Show(IWin32Window parent)
        {
            IFileDialog dialog = null;

            try
            {
                dialog = new NativeFileOpenDialog();
                dialog.SetOptions(FOS.FOS_PICKFOLDERS);
                if (dialog.Show(parent != null ? parent.Handle : IntPtr.Zero) == 0)
                {
                    string     result = string.Empty;
                    IShellItem item;
                    dialog.GetResult(out item);
                    return(GetFilePathFromShellItem(item));
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                if (dialog != null)
                {
                    Marshal.FinalReleaseComObject(dialog);
                }
            }
        }
예제 #4
0
        private CommonDialogResult RunVistaNativeDialog(IntPtr hwndOwner)
        {
            var nativeFileOpenDialog = new NativeFileOpenDialog();

            SetNativeDialogProperties(nativeFileOpenDialog);
            try
            {
                int hresult = nativeFileOpenDialog.Show(hwndOwner);

                //Create return information.
                if (hresult < 0)
                {
                    if ((uint)hresult == (uint)HRESULT.E_ERROR_CANCELLED)
                    {
                        return(CommonDialogResult.Cancel);
                    }

                    throw Marshal.GetExceptionForHR(hresult);
                }

                GetNativeDialogResult(nativeFileOpenDialog);
                return(CommonDialogResult.OK);
            }
            finally
            {
                if (nativeFileOpenDialog != null)
                {
                    Marshal.FinalReleaseComObject(nativeFileOpenDialog);
                }
            }
        }
예제 #5
0
        public DialogResult ShowDialog()
        {
            NativeFileOpenDialog dialog = null;

            try
            {
                // If the caller did not specify a starting path, or set it to null,
                // it is not healthy as it causes SHCreateItemFromParsingName to
                // throw E_INVALIDARG (0x80070057). Setting it to an empty string.
                //
                if (SelectedPath == null)
                {
                    SelectedPath = string.Empty;
                }

                dialog = new NativeFileOpenDialog();

                dialog.SetTitle(Title);

                object shellItem;
                // IShellItem GUID
                Guid guid    = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE");
                int  hresult = SHCreateItemFromParsingName(SelectedPath, IntPtr.Zero, ref guid, out shellItem);
                if ((uint)hresult != (uint)HRESULT.S_OK)
                {
                    throw Marshal.GetExceptionForHR(hresult);
                }
                dialog.SetFolder((IShellItem)shellItem);

                dialog.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_FORCEFILESYSTEM | FOS.FOS_FILEMUSTEXIST);

                IntPtr hWnd = new WindowInteropHelper(Owner).Handle;
                hresult = dialog.Show(hWnd);
                if (hresult < 0)
                {
                    if ((uint)hresult == (uint)HRESULT.E_CANCELLED)
                    {
                        return(DialogResult.Cancel);
                    }
                    throw Marshal.GetExceptionForHR(hresult);
                }

                string     path;
                IShellItem item;
                dialog.GetResult(out item);
                item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out path);
                SelectedPath = path;

                return(DialogResult.OK);
            }
            finally
            {
                if (dialog != null)
                {
                    Marshal.FinalReleaseComObject(dialog);
                }
            }
        }
예제 #6
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>true if the file could be opened; otherwise, false.</returns>
        protected override bool RunDialog(IntPtr hwndOwner)
        {
            if (_downlevelDialog != null)
            {
                return
                    (_downlevelDialog.ShowDialog(hwndOwner == IntPtr.Zero ? null : new WindowHandleWrapper(hwndOwner)) ==
                     DialogResult.OK);
            }

            IFileDialog dialog = null;

            try
            {
                dialog = new NativeFileOpenDialog();
                SetDialogProperties(dialog);
                int result = dialog.Show(hwndOwner);
                if (result < 0)
                {
                    if ((uint)result == NativeMethods.ERROR_CANCELLED)
                    {
                        return(false);
                    }
                    else
                    {
                        throw Marshal.GetExceptionForHR(result);
                    }
                }
                GetResult(dialog);
                return(true);
            }
            finally
            {
                if (dialog != null)
                {
                    Marshal.FinalReleaseComObject(dialog);
                }
            }
        }
예제 #7
0
        public DialogResult ShowDialog()
        {
            NativeFileOpenDialog dialog = null;

            try
            {
                // If the caller did not specify a starting path, or set it to null,
                // it is not healthy as it causes SHCreateItemFromParsingName to 
                // throw E_INVALIDARG (0x80070057). Setting it to an empty string.
                // 
                if (SelectedPath == null)
                    SelectedPath = string.Empty;

                dialog = new NativeFileOpenDialog();

                dialog.SetTitle(Title);

                object shellItem;
                // IShellItem GUID
                Guid guid = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE");
                int hresult = SHCreateItemFromParsingName(SelectedPath, IntPtr.Zero, ref guid, out shellItem);
                if ((uint)hresult != (uint)HRESULT.S_OK)
                    throw Marshal.GetExceptionForHR(hresult);
                dialog.SetFolder((IShellItem)shellItem);

                dialog.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_FORCEFILESYSTEM | FOS.FOS_FILEMUSTEXIST);

                IntPtr hWnd = new WindowInteropHelper(Owner).Handle;
                hresult = dialog.Show(hWnd);
                if (hresult < 0)
                {
                    if ((uint)hresult == (uint)HRESULT.E_CANCELLED)
                        return DialogResult.Cancel;
                    throw Marshal.GetExceptionForHR(hresult);
                }

                string path;
                IShellItem item;
                dialog.GetResult(out item);
                item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out path);
                SelectedPath = path;

                return DialogResult.OK;
            }
            finally 
            {
                if (dialog != null)
                    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>true if the file could be opened; otherwise, false.</returns>
        protected override bool RunDialog(IntPtr hwndOwner)
        {
            if( _downlevelDialog != null )
                return _downlevelDialog.ShowDialog(hwndOwner == IntPtr.Zero ? null : new WindowHandleWrapper(hwndOwner)) == DialogResult.OK;

            IFileDialog dialog = null;
            try
            {
                dialog = new NativeFileOpenDialog();
                SetDialogProperties(dialog);
                int result = dialog.Show(hwndOwner);
                if( result < 0 )
                {
                    if( (uint)result == NativeMethods.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);
            }
        }
예제 #9
0
		public static string Show(IWin32Window parent)
		{
			IFileDialog dialog = null;
			try
			{
				dialog = new NativeFileOpenDialog();
				dialog.SetOptions(FOS.FOS_PICKFOLDERS);
				if(dialog.Show(parent != null ? parent.Handle : IntPtr.Zero) == 0)
				{
					string result = string.Empty;
					IShellItem item;
					dialog.GetResult(out item);
					return GetFilePathFromShellItem(item);
				}
				else
				{
					return null;
				}
			}
			finally
			{
				if(dialog != null)
				{
					Marshal.FinalReleaseComObject(dialog);
				}
			}
		}
예제 #10
0
 private bool RunDialog(IntPtr owner)
 {
     IFileDialog dialog = null;
     try
     {
         dialog = new NativeFileOpenDialog();
         SetDialogProperties(dialog);
         int result = dialog.Show(owner);
         if (result < 0)
         {
             if ((uint) result == (uint) HRESULT.ERROR_CANCELLED)
                 return false;
             else
                 throw Marshal.GetExceptionForHR(result);
         }
         GetResult(dialog);
         return true;
     }
     finally
     {
         if (dialog != null)
             Marshal.FinalReleaseComObject(dialog);
     }
 }