Eric Sherman
asked on
Browse Directory View code published earlier
This code was previously posted by rockiroads ...
I was working on something similar and ran accross this coded below that was previously posted. The code below basically allows the user to Browse Directory Tree and stores the path/filename. This works just fine and the question I have is ....
If I wanted to open the Browse Directory Window with a folder already open, can this be done with your code?? In other words, when the Browse Directory Window opens, I want the Folder "C:\ImportFiles" already selected and opened.
Thanks,
ET
Private Type BROWSEINFO
hOwner As Long 'handle to window opening dialog
pidlRoot As Long 'A pointer to an ITEMIDLIST structure (a.k.a. a PIDL) which identifies the root folder for the dialog box. The user's selection is limited to this folder and any subfolders under it
pszDisplayName As String 'Receives the null-terminated display name of the folder the user selects. This must be initialized to an empty string of at least 260 characters
lpszTitle As String 'The title of the dialog box, which will appear above the folder tree
ulFlags As Long 'See BIF flags above
lpfn As Long 'A pointer to the BrowseCallbackProc callback function used to process the dialog box's messages. To use the default behavior, set this to 0
lParam As Long 'An application-defined value to pass to the callback function, if needed
iImage As Long 'Receives the index of the system image associated with the user's selection
End Type
Private Declare Function SHBrowseForFolder Lib "shell32" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pIdl As Long, ByVal pszPath As String) As Long
Public Function BrowseDirectory() As String
Dim tBI As BROWSEINFO
Dim pIdl As Long
Dim sPath As String
tBI.lpszTitle = "Browse Folders"
tBI.ulFlags = &H4000
pIdl = SHBrowseForFolder(tBI)
'Check for cancel
If pIdl = 0 Then Exit Function
'Get selected path from the id list, will rtn False if the id list can't be converted
sPath = String$(260, 0)
SHGetPathFromIDList ByVal pIdl, ByVal sPath
' Display the path and the name of the selected folder
BrowseDirectory = Left(sPath, InStr(sPath, vbNullChar) - 1)
End Function
I was working on something similar and ran accross this coded below that was previously posted. The code below basically allows the user to Browse Directory Tree and stores the path/filename. This works just fine and the question I have is ....
If I wanted to open the Browse Directory Window with a folder already open, can this be done with your code?? In other words, when the Browse Directory Window opens, I want the Folder "C:\ImportFiles" already selected and opened.
Thanks,
ET
Private Type BROWSEINFO
hOwner As Long 'handle to window opening dialog
pidlRoot As Long 'A pointer to an ITEMIDLIST structure (a.k.a. a PIDL) which identifies the root folder for the dialog box. The user's selection is limited to this folder and any subfolders under it
pszDisplayName As String 'Receives the null-terminated display name of the folder the user selects. This must be initialized to an empty string of at least 260 characters
lpszTitle As String 'The title of the dialog box, which will appear above the folder tree
ulFlags As Long 'See BIF flags above
lpfn As Long 'A pointer to the BrowseCallbackProc callback function used to process the dialog box's messages. To use the default behavior, set this to 0
lParam As Long 'An application-defined value to pass to the callback function, if needed
iImage As Long 'Receives the index of the system image associated with the user's selection
End Type
Private Declare Function SHBrowseForFolder Lib "shell32" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pIdl As Long, ByVal pszPath As String) As Long
Public Function BrowseDirectory() As String
Dim tBI As BROWSEINFO
Dim pIdl As Long
Dim sPath As String
tBI.lpszTitle = "Browse Folders"
tBI.ulFlags = &H4000
pIdl = SHBrowseForFolder(tBI)
'Check for cancel
If pIdl = 0 Then Exit Function
'Get selected path from the id list, will rtn False if the id list can't be converted
sPath = String$(260, 0)
SHGetPathFromIDList ByVal pIdl, ByVal sPath
' Display the path and the name of the selected folder
BrowseDirectory = Left(sPath, InStr(sPath, vbNullChar) - 1)
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Much appreciated rockiroads ...
It works and I just need to review the callback function as I'm not that familiar with it.
Again, thanks.
ET
It works and I just need to review the callback function as I'm not that familiar with it.
Again, thanks.
ET
I guess u want the answer?