VB 在ListBox加载目录与文件列表 | 雨律在线
'*************************************************************
'******
'****** 类型:模块 作者:JiaJia Http://Www.YuLv.Net
'******
'*************************************************************
Option Explicit

'API声明
Private Declare Function SendMessageA Lib "user32" (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:\*.*"

 
目前有0条回应
Comment
Trackback
你目前的身份是游客,请输入昵称和电邮!