VB 在ListBox加载目录与文件列表
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
'常量
Private Const LB_DIR = &H18D
Private Const DDL_DRIVES = &H4000 '磁盘
Private Const DDL_DIRECTORY = &H10 '文件夹
Private Const DDL_ARCHIVE = &H20
Private Const DDL_EXCLUSIVE = &H8000&
Private Const DDL_READWRITE = &H0 '读写
Private Const DDL_READONLY = &H1 '只读
Private Const DDL_HIDDEN = &H2 '隐藏
Private Const DDL_SYSTEM = &H4 '系统
Private Const DDL_POSTMSGS = &H2000
'-------------------------------------------------
'功能:用ListBox控件加载文件列表
'参数:lst - 指定的ListBox控件
' sPath - 指定目录
'-------------------------------------------------
Private Sub MyListBoxLoadFolder(ByRef lst As ListBox, _
ByVal sPath As String, _
Optional bShowFolders As Boolean = True)
On Error Resume Next
Dim lngReturn As Long
Dim lngFlags As Long
If bShowFolders = False Then
lngFlags = DDL_EXCLUSIVE Or DDL_ARCHIVE Or DDL_SYSTEM Or DDL_HIDDEN
Else
lngFlags = DDL_EXCLUSIVE Or DDL_ARCHIVE Or DDL_SYSTEM Or DDL_HIDDEN Or DDL_DIRECTORY
End If
'清空列表
lst.Clear
'开始装载文件列表
lngReturn = SendMessageA(lst.hWnd, LB_DIR, lngFlags, ByVal sPath)
End Sub
举例:
MyListBoxLoadFolder List1, "c:\*.*"