コード例 #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 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);
                }
            }
        }
コード例 #3
0
        private void GetNativeDialogResult(NativeFileOpenDialog nativeFileOpenDialog)
        {
            IShellItem item;

            nativeFileOpenDialog.GetResult(out item);
            item.GetDisplayName(CommonDialogNativeMethods.SIGDN.SIGDN_FILESYSPATH, out m_FolderPath);
        }
コード例 #4
0
        private void SetNativeDialogProperties(NativeFileOpenDialog nativeFileOpenDialog)
        {
            //Set Title
            if (!string.IsNullOrEmpty(m_Title))
            {
                nativeFileOpenDialog.SetTitle(m_Title);
            }

            //Set Folder
            if (!string.IsNullOrEmpty(m_FolderPath))
            {
                if (System.IO.Directory.Exists(m_FolderPath))
                {
                    nativeFileOpenDialog.SetFolder(CreateShellItemFromParsingName(m_FolderPath));
                }
                else
                {
                    string parent = System.IO.Path.GetDirectoryName(m_FolderPath);
                    if (parent != null && System.IO.Directory.Exists(parent))
                    {
                        string folder = System.IO.Path.GetFileName(m_FolderPath);
                        nativeFileOpenDialog.SetFolder(CreateShellItemFromParsingName(parent));
                        nativeFileOpenDialog.SetFileName(folder);
                    }
                }
            }

            //Apply option bitflags
            nativeFileOpenDialog.SetOptions(GetNativeDialogFlags());
        }
コード例 #5
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);
                }
            }
        }
コード例 #6
0
 internal override void InitializeNativeFileDialog()
 {
     if (openDialogCoClass == null)
     {
         openDialogCoClass = new NativeFileOpenDialog();
     }
 }
コード例 #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);
                }
            }
        }
コード例 #8
0
 public DynamoOpenFileDialog(DynamoViewModel model)
 {
     this.model = model;
     _dialog = new NativeFileOpenDialog();
     IFileDialogCustomize customize = (IFileDialogCustomize) _dialog;
     customize.AddCheckButton(RunManualCheckboxId, 
         Dynamo.Wpf.Properties.Resources.FileDialogManualMode,
         model.PreferenceSettings.OpenFileInManualExecutionMode);
 }
コード例 #9
0
        public DynamoOpenFileDialog(DynamoViewModel model)
        {
            this.model = model;
            _dialog    = new NativeFileOpenDialog();
            IFileDialogCustomize customize = (IFileDialogCustomize)_dialog;

            customize.AddCheckButton(RunManualCheckboxId,
                                     Dynamo.Wpf.Properties.Resources.FileDialogManualMode,
                                     model.PreferenceSettings.OpenFileInManualExecutionMode);
        }
コード例 #10
0
        private static String[] ShowDialog(IntPtr parentWindowHandle, String title, String initialDirectory, String defaultFileName, IReadOnlyCollection <Filter> filters, Int32 selectedFilterZeroBasedIndex, FileOpenOptions flags)
        {
            NativeFileOpenDialog nfod = new NativeFileOpenDialog();

            try
            {
                return(ShowDialogInner(nfod, parentWindowHandle, title, initialDirectory, defaultFileName, filters, selectedFilterZeroBasedIndex, flags));
            }
            finally
            {
                Marshal.ReleaseComObject(nfod);
            }
        }
コード例 #11
0
        /// <summary>Shows the folder browser dialog. Returns null if the dialog cancelled. Otherwise returns the selected path.</summary>
        public static String ShowDialog(IntPtr parentHWnd, String title, String initialDirectory)
        {
            NativeFileOpenDialog nfod = new NativeFileOpenDialog();

            try
            {
                return(ShowDialogInner(nfod, parentHWnd, title, initialDirectory));
            }
            finally
            {
                Marshal.ReleaseComObject(nfod);
            }
        }
コード例 #12
0
        private static IReadOnlyList <String> ShowDialog(IntPtr parentHWnd, String title, String initialDirectory, String defaultFileName, IReadOnlyCollection <Filter> filters, Int32?selectedFilterZeroBasedIndex, FileOpenOptions flags)
#endif
        {
            NativeFileOpenDialog nfod = new NativeFileOpenDialog();

            try
            {
                return(ShowDialogInner(nfod, parentHWnd, title, initialDirectory, defaultFileName, filters, selectedFilterZeroBasedIndex: selectedFilterZeroBasedIndex ?? (-1), flags));
            }
            finally
            {
                _ = Marshal.ReleaseComObject(nfod);
            }
        }
コード例 #13
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);
                }
            }
        }
コード例 #14
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);
     }
 }
コード例 #15
0
ファイル: VistaPickFolderDialog.cs プロジェクト: Kuzq/gitter
		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);
				}
			}
		}
コード例 #16
0
 public DialogHolder()
 {
     State = NativeDialogShowState.PreShow;
     Dialog = new NativeFileOpenDialog();
     State = NativeDialogShowState.Showing;
 }
コード例 #17
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);
            }
        }
コード例 #18
0
 internal void InitializeNativeFileDialog()
 {
     openDialogCoClass = new NativeFileOpenDialog();
 }
コード例 #19
0
 internal void InitializeNativeFileDialog()
 {
     openDialogCoClass = new NativeFileOpenDialog();
 }
コード例 #20
0
 internal override void InitializeNativeFileDialog()
 {
     if (openDialogCoClass == null)
     {
         openDialogCoClass = new NativeFileOpenDialog();
     }
 }
コード例 #21
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 System.Runtime.InteropServices.Marshal.GetExceptionForHR(result);
                } 
                GetResult(dialog);
                return true;
            }
            finally
            {
                if( dialog != null )
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(dialog);
            }
        }