Click to See Complete Forum and Search --> : folder browser dialog, like setup programs


Lonely Wolf
December 15th, 1999, 10:09 AM
When during a setup you click the browse button to select folder to install to, appear a dialog with only folders like a treeview.
How can I call that dialog box?
thanks

Aaron Young
December 15th, 1999, 03:02 PM
You can use the SHBrowseForFolder API, here's an example I've put together..

In a Module..

option Explicit

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

private Const BIF_RETURNONLYFSDIRS = 1

public Function BrowseForFolder(byval lHwnd as Long, byval sPrompt as string) as string
Dim tBI as BROWSEINFO
Dim lList as Long
Dim lResult as Long
Dim sPath as string

With tBI
.hwndOwner = lHwnd
.lpszTitle = lStrCat(sPrompt, Chr(0))
.ulFlags = BIF_RETURNONLYFSDIRS
End With
lList = SHBrowseForFolder(tBI)
If lList then
sPath = Space(260)
lResult = SHGetPathFromIDList(lList, sPath)
Call CoTaskMemFree(lList)
sPath = Left$(sPath, InStr(sPath, Chr(0)) - 1)
End If
BrowseForFolder = sPath
End Function



In your Form..

private Sub Command1_Click()
Caption = BrowseForFolder(hwnd, "Select Directory..")
End Sub





Aaron Young
Analyst Programmer
adyoung@win.bright.net
aarony@redwingsoftware.com