标题: Presenting a List of Directories to a User using the Windows Shell Browse for [打印本页] 作者: tmtony 时间: 2005-8-5 20:01 标题: Presenting a List of Directories to a User using the Windows Shell Browse for 标题resenting a List of Directories to a User using the Windows Shell Browse for Folder Dialog
原作者:ATTAC Consulting Group
You can provide Users with a simple Directory dialog rather than using the standard File Open or File Save As dialogs from the common dialog suite which shows both files and directories. To do this you use the Directory dialog built into the Shell OLE container. Here's the code to do it:
In the declarations page of a module, add the following declares (an "_" means line continuation): Type shellBrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As String
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Const BIF_RETURNONLYFSDIRS = 1
Const MAX_PATH = 260
Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Declare Function SHBrowseForFolder Lib "shell32" (lpbi As shellBrowseInfo) As Long
Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, _
ByVal lpBuffer As String) As Long
Then use the following function, supplying it the title you want to use for the dialog, and the handle of the calling form. (use the Me.hwnd property of the form): Public Function GetFolder(dlgTitle As String, Frmhwnd as Long) As String
Call CoTaskMemFree(lngIDList) 'this frees the ole pointer to lngIDlist
intNullchr = InStr(strFolder, vbNullChar)
If intNullchr Then
strFolder = Left$(strFolder, intNullChr - 1)
End If
End If
GetFolder = strFolder
End FunctionThis function will return the path to the folder selected, so long as it is not a system folder such as the printers folder. 作者: 爱情插班生 时间: 2005-8-9 16:12
标题:当用户仅需使用到外部文件夹时,我们可以引用系统窗口浏览器显示一列文件夹目录对话框。