sorry to do this to ya... i put in the code but it didnt work
Private Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Public Function BrowseForFolder(ByVal strInitDrive As String, ByVal lngHwndOwner As Long) As String
'Opens the browse for folder dialog
Dim iNull As Integer, lpIDList As Long
Dim sPath As String, udtBI As BrowseInfo
With udtBI
.hWndOwner = lngHwndOwner
'lstrcat appends the two strings and returns the memory address
.lpszTitle = lstrcat(strInitDrive, "")
'Return only if the user selected a directory
.ulFlags = BIF_RETURNONLYFSDIRS
End With
'Show the 'Browse for folder' dialog
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
'Get the path from the IDList
SHGetPathFromIDList lpIDList, sPath
'free the block of memory
CoTaskMemFree lpIDList
iNull = InStr(sPath, vbNullChar)
If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If
BrowseForFolder = sPath
End Function
i put into a module
and
Dim strFolder As String
strFolder = BrowserForFolder("C:\", Me.hWnd)
MsgBox strFolder
i put into the button but i get a "sub or function not defined" error and it highlights this line:
strFolder = BrowseForFolder("C:\", Me.hWnd)
and this is highlighted with an yellow arrow
Private Sub ButRootFolder_Click()
am i doin it right?
also, do do you set the default path for the code above?
Last edited by Colonel Klink; Aug 31st, 2002 at 07:36 AM.
The attached module is basically the same thing as what axion_sa has posted except it also lets you choose the default directory. The useage for it is:
VB Code:
Private Sub Command1_Click()
Dim strPath As String
strPath = GetFolderPath(Me, "C:\program files")
MsgBox strPath
End Sub
The default directory is optional and will open to the c drive if left blank.
Re: selecting folders only with common dialog control
Suppose first time I selected folder "D:\Test". Now when I go for browsing again, I want that in browser window folder "D:\Test" is preselected and I should be able to either select a folder above that (i.e. its parent folder) or a folder below that (i.e. its sub folder). How to do this? i.e. when I go for browsing a folder earlier selected folder is shown preselected in this window.
Re: selecting folders only with common dialog control
Requires setting the lpfnCallback member of the BrowseInfo structure and then responding to messages it sends you. Suggest searching forum and/or google for: BrowseInfo lpfnCallback BFFM_SETSELECTION