//***************************************************************************** //*** BrowseForFolder.pkg *** //*** *** //*** Author: Vincent Oorsprong / Ben Weijers *** //*** Data Access Europe *** //*** August 2001 *** //*** *** //*** Purpose: *** //*** Exposes the SHBrowseForFolder function to select directories. *** //***************************************************************************** Use Windows Use Dll //*** Create the type Type BROWSEINFO Field BROWSEINFO.hwndOwner As Handle Field BROWSEINFO.pidlRoot As Pointer Field BROWSEINFO.pszDisplayName As Pointer Field BROWSEINFO.lpszTitle As Pointer Field BROWSEINFO.ulFlags As Integer Field BROWSEINFO.lpfn As Pointer Field BROWSEINFO.lParam As DWord Field BROWSEINFO.iImage As Integer End_Type // BROWSEINFO //*** Define the flags Define BIF_RETURNONLYFSDIRS For |CI$0001 // For finding a folder to start document searching Define BIF_DONTGOBELOWDOMAIN For |CI$0002 // For starting the Find Computer Define BIF_STATUSTEXT For |CI$0004 Define BIF_RETURNFSANCESTORS For |CI$0008 Define BIF_BROWSEFORCOMPUTER For |CI$1000 // Browsing for Computers. Define BIF_BROWSEFORPRINTER For |CI$2000 // Browsing for Printers // message from browser Define BFFM_INITIALIZED For 1 Define BFFM_SELCHANGED For 2 // messages to browser Define BFFM_SETSTATUSTEXT For (WM_USER + 100) Define BFFM_ENABLEOK For (WM_USER + 101) Define BFFM_SETSELECTION For (WM_USER + 102) Define MAX_PATH For 260 External_function SHBrowseForFolder "SHBrowseForFolder" Shell32.Dll ; Pointer lpbi ; Returns Pointer External_function SHGetPathFromIDList "SHGetPathFromIDList" Shell32.Dll ; Pointer pidl ; Pointer pszPath ; Returns Integer External_Function CoTaskMemFree "CoTaskMemFree" Ole32.Dll ; Pointer pv ; Returns Integer //***************************************************************************** //*** Function: BrowseForFolder *** //*** Purpose : Browse for a folder. *** //***************************************************************************** Function BrowseForFolder Handle hWnd String sTitle Integer iFlags Returns String String sFolderPathName String sBrowseInfo Pointer lpsFolderPathName Pointer lpsTitle Pointer lpBrowseInfo Pointer lpReturnValue Integer iRetval //*** Zero the structure ZeroType BROWSEINFO To sBrowseInfo GetAddress Of sBrowseInfo To lpBrowseInfo //*** Allocate a string to put the result Move (Repeat (Character (0), MAX_PATH)) To sFolderPathName GetAddress Of sFolderPathName To lpsFolderPathName //*** Make the tile a C string and get its address If (Right(sTitle, 1) <> Character(0)) ; Move (Append(sTitle, Character(0))) To sTitle GetAddress Of sTitle To lpsTitle //*** Fill the browseinfo structure Put hWnd To sBrowseInfo At BROWSEINFO.hwndOwner Put lpsFolderPathName To sBrowseInfo At BROWSEINFO.pszDisplayName Put lpsTitle To sBrowseInfo At BROWSEINFO.lpszTitle Put iFlags To sBrowseInfo At BROWSEINFO.ulFlags //*** Browse and get the result Move (SHBrowseForFolder (lpBrowseInfo)) To lpReturnValue Move (SHGetPathFromIDList (lpReturnValue, lpsFolderPathName)) To iRetval Move (CoTaskMemFree (lpReturnValue)) To iRetval If (iRetval <> Dffalse) Begin Move (Cstring (sFolderPathName)) To sFolderPathName End Else Begin Move "" To sFolderPathName End Function_Return sFolderPathName End_Function // BrowseForFolder