/// <summary>Initializes a new instance of the <see cref="BROWSEINFO"/> struct.</summary> /// <param name="hWnd">A handle to the owner window for the dialog box.</param> /// <param name="rootPidl">A PIDL that specifies the location of the root folder from which to start browsing.</param> /// <param name="title">The string that is displayed above the tree view control in the dialog box.</param> /// <param name="flags">Flags that specify the options for the dialog box.</param> /// <param name="callback">The callback function that the dialog box calls when an event occurs..</param> /// <param name="displayNameBuffer">Buffer that receives the display name of the folder selected by the user.</param> public BROWSEINFO(HWND hWnd, IntPtr rootPidl, string title, BrowseInfoFlag flags, BrowseCallbackProc callback, SafeCoTaskMemString displayNameBuffer) { hwndOwner = hWnd; pidlRoot = rootPidl; pszDisplayName = (IntPtr)displayNameBuffer; lpszTitle = title; ulFlags = flags; lpfn = callback; lParam = IntPtr.Zero; iImage = 0; }
protected override bool RunDialog(IntPtr hWndOwner) { IntPtr zero = IntPtr.Zero; bool flag = false; NativeMethods.SHGetSpecialFolderLocation(hWndOwner, (int)this.rootFolder, ref zero); if (zero == IntPtr.Zero) { NativeMethods.SHGetSpecialFolderLocation(hWndOwner, 0, ref zero); if (zero == IntPtr.Zero) { throw new InvalidOperationException("FolderBrowserDialogNoRootFolder"); } } int num = 0x40; if (!this.showNewFolderButton) { num += 0x200; } IntPtr pidl = IntPtr.Zero; IntPtr hglobal = IntPtr.Zero; IntPtr pszPath = IntPtr.Zero; try { NativeMethods.BROWSEINFO lpbi = new NativeMethods.BROWSEINFO(); hglobal = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize)); pszPath = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize)); this.callback = new BrowseCallbackProc(this.FolderBrowserDialog_BrowseCallbackProc); lpbi.pidlRoot = zero; lpbi.hwndOwner = hWndOwner; lpbi.pszDisplayName = hglobal; lpbi.lpszTitle = this.descriptionText; lpbi.ulFlags = num; lpbi.lpfn = this.callback; lpbi.lParam = IntPtr.Zero; lpbi.iImage = 0; pidl = NativeMethods.SHBrowseForFolder(lpbi); if (pidl != IntPtr.Zero) { NativeMethods.SHGetPathFromIDList(pidl, pszPath); this.selectedPathNeedsCheck = true; this.selectedPath = Marshal.PtrToStringAuto(pszPath); flag = true; } } finally { NativeMethods.IMalloc sHMalloc = GetSHMalloc(); sHMalloc.Free(zero); if (pidl != IntPtr.Zero) { sHMalloc.Free(pidl); } if (pszPath != IntPtr.Zero) { Marshal.FreeHGlobal(pszPath); } if (hglobal != IntPtr.Zero) { Marshal.FreeHGlobal(hglobal); } this.callback = null; } return(flag); }
/// <summary> /// When overridden in a derived class, 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 dialog box was successfully run; otherwise, false. /// </returns> protected override bool RunDialog(IntPtr hwndOwner) { var zero = IntPtr.Zero; var flag = false; SHGetSpecialFolderLocation(hwndOwner, (int)rootFolder, ref zero); if (zero == IntPtr.Zero) { SHGetSpecialFolderLocation(hwndOwner, 0, ref zero); if (zero == IntPtr.Zero) { throw new InvalidOperationException( "Folder Browser Dialog: no root folder"); } } if (Control.CheckForIllegalCrossThreadCalls && Application.OleRequired() != ApartmentState.STA) { throw new ThreadStateException("Debugging exception only: Thread must be STA"); } var pidl = IntPtr.Zero; var hglobal = IntPtr.Zero; var pszPath = IntPtr.Zero; try { var lpbi = new BROWSEINFO(); hglobal = Marshal.AllocHGlobal(260 * Marshal.SystemDefaultCharSize); pszPath = Marshal.AllocHGlobal(260 * Marshal.SystemDefaultCharSize); callback = new BrowseCallbackProc(FolderBrowserDialog_BrowseCallbackProc); lpbi.pidlRoot = zero; lpbi.hwndOwner = hwndOwner; lpbi.pszDisplayName = hglobal; lpbi.lpszTitle = descriptionText; lpbi.ulFlags = (int)CreationFlags; lpbi.lpfn = callback; lpbi.lParam = IntPtr.Zero; lpbi.iImage = 0; pidl = SHBrowseForFolder(lpbi); if (pidl != IntPtr.Zero) { SHGetPathFromIDList(pidl, pszPath); selectedPathNeedsCheck = true; selectedPath = Marshal.PtrToStringAuto(pszPath); flag = true; } } finally { var sHMalloc = GetSHMalloc(); sHMalloc.Free(zero); if (pidl != IntPtr.Zero) { sHMalloc.Free(pidl); } if (pszPath != IntPtr.Zero) { Marshal.FreeHGlobal(pszPath); } if (hglobal != IntPtr.Zero) { Marshal.FreeHGlobal(hglobal); } callback = null; } return(flag); }
/// <summary></summary> protected override bool RunDialog(IntPtr hWndOwner) { IntPtr zero = IntPtr.Zero; bool flag = false; Win32.SHGetSpecialFolderLocation(hWndOwner, (int)this.mRootFolder, ref zero); if (zero == IntPtr.Zero) { Win32.SHGetSpecialFolderLocation(hWndOwner, 0, ref zero); if (zero == IntPtr.Zero) { throw new InvalidOperationException("No Root Folder."); } } BrowseInfoFlag flags = BrowseInfoFlag.NewUserInterface; if (!this.mShowNewFolderButton) { flags |= BrowseInfoFlag.NoNewFolderButton; } if (this.mIncludeFiles) { flags |= BrowseInfoFlag.BrowseEverything; } if (Control.CheckForIllegalCrossThreadCalls && (Application.OleRequired() != ApartmentState.STA)) { throw new ThreadStateException("Thread Must Be STA."); } IntPtr pidl = IntPtr.Zero; IntPtr hglobal = IntPtr.Zero; IntPtr pszPath = IntPtr.Zero; try { this.mCurrentCallback = new BrowseCallbackProc(this.FolderBrowserDialog_BrowseCallbackProc); hglobal = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize)); pszPath = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize)); BROWSEINFO lpbi = new BROWSEINFO(); lpbi.pidlRoot = zero; lpbi.hwndOwner = hWndOwner; lpbi.pszDisplayName = hglobal; lpbi.lpszTitle = this.mDescriptionText; lpbi.ulFlags = (int)flags; lpbi.lpfn = this.mCurrentCallback; lpbi.lParam = IntPtr.Zero; lpbi.iImage = 0; pidl = Win32.SHBrowseForFolder(lpbi); if (pidl != IntPtr.Zero) { Win32.SHGetPathFromIDList(pidl, pszPath); this.mSelectedPathNeedsCheck = true; this.mSelectedPath = Marshal.PtrToStringAuto(pszPath); flag = true; } } finally { IMalloc sHMalloc = GetSHMalloc(); sHMalloc.Free(zero); if (pidl != IntPtr.Zero) { sHMalloc.Free(pidl); } if (pszPath != IntPtr.Zero) { Marshal.FreeHGlobal(pszPath); } if (hglobal != IntPtr.Zero) { Marshal.FreeHGlobal(hglobal); } this.mCurrentCallback = null; } return(flag); }
protected override bool RunDialog(IntPtr hWndOwner) { IntPtr zero = IntPtr.Zero; bool result = false; SHGetSpecialFolderLocation(hWndOwner, (int)this.rootFolder, ref zero); if (zero == IntPtr.Zero) { SHGetSpecialFolderLocation(hWndOwner, 0, ref zero); if (zero == IntPtr.Zero) { throw new InvalidOperationException("FolderBrowserDialogExNoRootFolder"); } } int num = 64; if (!this.showNewFolderButton) { num += 512; } if (Control.CheckForIllegalCrossThreadCalls && Application.OleRequired() != ApartmentState.STA) { throw new ThreadStateException("ThreadMustBeSTA"); } IntPtr intPtr = IntPtr.Zero; IntPtr intPtr2 = IntPtr.Zero; IntPtr intPtr3 = IntPtr.Zero; try { num |= 0x00000010; // BIF_EDITBOX num |= 0x00000040; // BIF_NEWDIALOGSTYLE BROWSEINFO bROWSEINFO = new BROWSEINFO(); intPtr2 = Marshal.AllocHGlobal(260 * Marshal.SystemDefaultCharSize); intPtr3 = Marshal.AllocHGlobal(260 * Marshal.SystemDefaultCharSize); this.callback = new BrowseCallbackProc(this.FolderBrowserDialogEx_BrowseCallbackProc); bROWSEINFO.pidlRoot = zero; bROWSEINFO.hwndOwner = hWndOwner; bROWSEINFO.pszDisplayName = intPtr2; bROWSEINFO.lpszTitle = this.descriptionText; bROWSEINFO.ulFlags = num; bROWSEINFO.lpfn = this.callback; bROWSEINFO.lParam = IntPtr.Zero; bROWSEINFO.iImage = 0; intPtr = SHBrowseForFolder(bROWSEINFO); if (intPtr != IntPtr.Zero) { SHGetPathFromIDList(intPtr, intPtr3); this.selectedPathNeedsCheck = true; this.selectedPath = Marshal.PtrToStringAuto(intPtr3); result = true; } } finally { CoTaskMemFree(zero); if (intPtr != IntPtr.Zero) { CoTaskMemFree(intPtr); } if (intPtr3 != IntPtr.Zero) { Marshal.FreeHGlobal(intPtr3); } if (intPtr2 != IntPtr.Zero) { Marshal.FreeHGlobal(intPtr2); } this.callback = null; } return(result); }
/// <summary> /// When overridden in a derived class, 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 dialog box was successfully run; otherwise, false. /// </returns> protected override bool RunDialog(IntPtr hwndOwner) { IntPtr zero = IntPtr.Zero; bool flag = false; SHGetSpecialFolderLocation(hwndOwner, (int)rootFolder, ref zero); if (zero == IntPtr.Zero) { SHGetSpecialFolderLocation(hwndOwner, 0, ref zero); if (zero == IntPtr.Zero) throw new InvalidOperationException( "Folder Browser Dialog: no root folder"); } //int flags = 0x40; //if (!showNewFolderButton) flags += 0x200; if (Control.CheckForIllegalCrossThreadCalls && (Application.OleRequired() != ApartmentState.STA)) throw new ThreadStateException("Debugging exception only: Thread must be STA"); IntPtr pidl = IntPtr.Zero; IntPtr hglobal = IntPtr.Zero; IntPtr pszPath = IntPtr.Zero; try { BROWSEINFO lpbi = new BROWSEINFO(); hglobal = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize)); pszPath = Marshal.AllocHGlobal((int)(260 * Marshal.SystemDefaultCharSize)); callback = new BrowseCallbackProc(FolderBrowserDialog_BrowseCallbackProc); lpbi.pidlRoot = zero; lpbi.hwndOwner = hwndOwner; lpbi.pszDisplayName = hglobal; lpbi.lpszTitle = descriptionText; lpbi.ulFlags = (int)flags; lpbi.lpfn = callback; lpbi.lParam = IntPtr.Zero; lpbi.iImage = 0; pidl = SHBrowseForFolder(lpbi); if (pidl != IntPtr.Zero) { SHGetPathFromIDList(pidl, pszPath); selectedPathNeedsCheck = true; selectedPath = Marshal.PtrToStringAuto(pszPath); flag = true; } } finally { IMalloc sHMalloc = GetSHMalloc(); sHMalloc.Free(zero); if (pidl != IntPtr.Zero) sHMalloc.Free(pidl); if (pszPath != IntPtr.Zero) Marshal.FreeHGlobal(pszPath); if (hglobal != IntPtr.Zero) Marshal.FreeHGlobal(hglobal); callback = null; } return flag; }
protected override bool RunDialog(IntPtr hWndOwner) { IntPtr zero = IntPtr.Zero; bool result = false; SHGetSpecialFolderLocation(hWndOwner, (int)this.rootFolder, ref zero); if (zero == IntPtr.Zero) { SHGetSpecialFolderLocation(hWndOwner, 0, ref zero); if (zero == IntPtr.Zero) { throw new InvalidOperationException("FolderBrowserDialogExNoRootFolder"); } } int num = 64; if (!this.showNewFolderButton) { num += 512; } if (Control.CheckForIllegalCrossThreadCalls && Application.OleRequired() != ApartmentState.STA) { throw new ThreadStateException("ThreadMustBeSTA"); } IntPtr intPtr = IntPtr.Zero; IntPtr intPtr2 = IntPtr.Zero; IntPtr intPtr3 = IntPtr.Zero; try { num |= 0x00000010; // BIF_EDITBOX num |= 0x00000040; // BIF_NEWDIALOGSTYLE BROWSEINFO bROWSEINFO = new BROWSEINFO(); intPtr2 = Marshal.AllocHGlobal(260 * Marshal.SystemDefaultCharSize); intPtr3 = Marshal.AllocHGlobal(260 * Marshal.SystemDefaultCharSize); this.callback = new BrowseCallbackProc(this.FolderBrowserDialogEx_BrowseCallbackProc); bROWSEINFO.pidlRoot = zero; bROWSEINFO.hwndOwner = hWndOwner; bROWSEINFO.pszDisplayName = intPtr2; bROWSEINFO.lpszTitle = this.descriptionText; bROWSEINFO.ulFlags = num; bROWSEINFO.lpfn = this.callback; bROWSEINFO.lParam = IntPtr.Zero; bROWSEINFO.iImage = 0; intPtr = SHBrowseForFolder(bROWSEINFO); if (intPtr != IntPtr.Zero) { SHGetPathFromIDList(intPtr, intPtr3); this.selectedPathNeedsCheck = true; this.selectedPath = Marshal.PtrToStringAuto(intPtr3); result = true; } } finally { CoTaskMemFree(zero); if (intPtr != IntPtr.Zero) { CoTaskMemFree(intPtr); } if (intPtr3 != IntPtr.Zero) { Marshal.FreeHGlobal(intPtr3); } if (intPtr2 != IntPtr.Zero) { Marshal.FreeHGlobal(intPtr2); } this.callback = null; } return result; }