protected override bool RunDialog(IntPtr hWndOwner) { bool flag = false; if (this._rootFolderLocation == IntPtr.Zero) { PInvoke.Shell32.SHGetSpecialFolderLocation(hWndOwner, (int)this._rootFolder, ref this._rootFolderLocation); if (this._rootFolderLocation == IntPtr.Zero) { PInvoke.Shell32.SHGetSpecialFolderLocation(hWndOwner, 0, ref this._rootFolderLocation); if (this._rootFolderLocation == IntPtr.Zero) { throw new InvalidOperationException("FolderBrowserDialogNoRootFolder"); } } } this._hwndEdit = IntPtr.Zero; if (this._dontIncludeNetworkFoldersBelowDomainLevel) { this._uiFlags += 2; } if (this._newStyle) { this._uiFlags += 0x40; } if (!this._showNewFolderButton) { this._uiFlags += 0x200; } if (this._showEditBox) { this._uiFlags += 0x10; } if (this._showBothFilesAndFolders) { this._uiFlags += 0x4000; } if (Control.CheckForIllegalCrossThreadCalls && (Application.OleRequired() != ApartmentState.STA)) { throw new ThreadStateException("DebuggingException: ThreadMustBeSTA"); } IntPtr zero = IntPtr.Zero; IntPtr hglobal = IntPtr.Zero; IntPtr pszPath = IntPtr.Zero; try { PInvoke.BROWSEINFO lpbi = new PInvoke.BROWSEINFO(); hglobal = Marshal.AllocHGlobal((int)(MAX_PATH * Marshal.SystemDefaultCharSize)); pszPath = Marshal.AllocHGlobal((int)(MAX_PATH * Marshal.SystemDefaultCharSize)); this._callback = new PInvoke.BrowseFolderCallbackProc(this.FolderBrowserCallback); lpbi.pidlRoot = this._rootFolderLocation; lpbi.Owner = hWndOwner; lpbi.pszDisplayName = hglobal; lpbi.Title = this._descriptionText; lpbi.Flags = this._uiFlags; lpbi.callback = this._callback; lpbi.lParam = IntPtr.Zero; lpbi.iImage = 0; zero = PInvoke.Shell32.SHBrowseForFolder(lpbi); if (((this._uiFlags & 0x2000) == 0x2000) || ((this._uiFlags & 0x1000) == 0x1000)) { this._selectedPath = Marshal.PtrToStringAuto(lpbi.pszDisplayName); return(true); } if (zero != IntPtr.Zero) { PInvoke.Shell32.SHGetPathFromIDList(zero, pszPath); this._selectedPathNeedsCheck = true; this._selectedPath = Marshal.PtrToStringAuto(pszPath); flag = true; } } finally { PInvoke.IMalloc sHMalloc = GetSHMalloc(); sHMalloc.Free(this._rootFolderLocation); this._rootFolderLocation = IntPtr.Zero; if (zero != IntPtr.Zero) { sHMalloc.Free(zero); } if (pszPath != IntPtr.Zero) { Marshal.FreeHGlobal(pszPath); } if (hglobal != IntPtr.Zero) { Marshal.FreeHGlobal(hglobal); } this._callback = null; } return(flag); }
public static extern IntPtr SHBrowseForFolder([In] PInvoke.BROWSEINFO lpbi);
protected override bool RunDialog(IntPtr hWndOwner) { bool flag = false; if (this._rootFolderLocation == IntPtr.Zero) { PInvoke.Shell32.SHGetSpecialFolderLocation(hWndOwner, (int) this._rootFolder, ref this._rootFolderLocation); if (this._rootFolderLocation == IntPtr.Zero) { PInvoke.Shell32.SHGetSpecialFolderLocation(hWndOwner, 0, ref this._rootFolderLocation); if (this._rootFolderLocation == IntPtr.Zero) { throw new InvalidOperationException("FolderBrowserDialogNoRootFolder"); } } } this._hwndEdit = IntPtr.Zero; if (this._dontIncludeNetworkFoldersBelowDomainLevel) { this._uiFlags += 2; } if (this._newStyle) { this._uiFlags += 0x40; } if (!this._showNewFolderButton) { this._uiFlags += 0x200; } if (this._showEditBox) { this._uiFlags += 0x10; } if (this._showBothFilesAndFolders) { this._uiFlags += 0x4000; } if (Control.CheckForIllegalCrossThreadCalls && (Application.OleRequired() != ApartmentState.STA)) { throw new ThreadStateException("DebuggingException: ThreadMustBeSTA"); } IntPtr zero = IntPtr.Zero; IntPtr hglobal = IntPtr.Zero; IntPtr pszPath = IntPtr.Zero; try { PInvoke.BROWSEINFO lpbi = new PInvoke.BROWSEINFO(); hglobal = Marshal.AllocHGlobal((int) (MAX_PATH*Marshal.SystemDefaultCharSize)); pszPath = Marshal.AllocHGlobal((int) (MAX_PATH*Marshal.SystemDefaultCharSize)); this._callback = new PInvoke.BrowseFolderCallbackProc(this.FolderBrowserCallback); lpbi.pidlRoot = this._rootFolderLocation; lpbi.Owner = hWndOwner; lpbi.pszDisplayName = hglobal; lpbi.Title = this._descriptionText; lpbi.Flags = this._uiFlags; lpbi.callback = this._callback; lpbi.lParam = IntPtr.Zero; lpbi.iImage = 0; zero = PInvoke.Shell32.SHBrowseForFolder(lpbi); if (((this._uiFlags & 0x2000) == 0x2000) || ((this._uiFlags & 0x1000) == 0x1000)) { this._selectedPath = Marshal.PtrToStringAuto(lpbi.pszDisplayName); return true; } if (zero != IntPtr.Zero) { PInvoke.Shell32.SHGetPathFromIDList(zero, pszPath); this._selectedPathNeedsCheck = true; this._selectedPath = Marshal.PtrToStringAuto(pszPath); flag = true; } } finally { PInvoke.IMalloc sHMalloc = GetSHMalloc(); sHMalloc.Free(this._rootFolderLocation); this._rootFolderLocation = IntPtr.Zero; if (zero != IntPtr.Zero) { sHMalloc.Free(zero); } if (pszPath != IntPtr.Zero) { Marshal.FreeHGlobal(pszPath); } if (hglobal != IntPtr.Zero) { Marshal.FreeHGlobal(hglobal); } this._callback = null; } return flag; }