- 中查找“往列表框中填入文件目录信息”更多相关内容
- 中查找“往列表框中填入文件目录信息”更多相关内容
- ·上一篇文章:文本框中光标位置的获得
- ·下一篇文章:拖动无标题窗口
往列表框中填入文件目录信息
Note however that the constant value for ''READWRITE'' is 0, the same as the vb constant ''Archive''. In VB you can not mask out the archive files to only return hidden files (for example). But by using the API value DDL_EXCLUSIVE Or''d with the type to be listed, you have control over the display of files.
The added bonus is that this method is instantaneous.
Add the following code to a BAS module:
---------------------------------------------------------------
Public Declare Function SendMessageStr Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long
Public Declare Function SendMessageLong Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Public Const LB_DIR = &H18D
Public Const LB_RESETCONTENT = &H184
Public Const DDL_READWRITE = &H0
Public Const DDL_READONLY = &H1
Public Const DDL_HIDDEN = &H2
Public Const DDL_SYSTEM = &H4
Public Const DDL_DIRECTORY = &H10
Public Const DDL_ARCHIVE = &H20
Public Const DDL_DRIVES = &H4000
Public Const DDL_EXCLUSIVE = &H8000
Public Const DDL_POSTMSGS = &H2000
Public Const DDL_FLAGS = DDL_ARCHIVE Or DDL_DIRECTORY
''--end block--
-------------------------------------------------------------------
Create a form containing six command buttons in a control array (Command1(0) - Command1(5)), and a listbox. Add the following code to the form:
-------------------------------------------------------------------
Private Sub Command1_Click(Index As Integer)
Dim r As Long
Dim DDL_FLAGS As Long
Dim searchPath As String
searchPath = "c:\win\*.*"
Select Case Index
Case 0: DDL_FLAGS = DDL_EXCLUSIVE Or DDL_ARCHIVE
Case 1: DDL_FLAGS = DDL_EXCLUSIVE Or DDL_ARCHIVE Or DDL_DIRECTORY
Case 2: DDL_FLAGS = DDL_EXCLUSIVE Or DDL_HIDDEN
Case 3: DDL_FLAGS = DDL_EXCLUSIVE Or DDL_SYSTEM
Case 4: DDL_FLAGS = DDL_EXCLUSIVE Or DDL_DIRECTORY
Case 5: DDL_FLAGS = DDL_EXCLUSIVE Or DDL_DRIVES
Case Else
End Select
''clear and populate the listbox
Call SendMessageLong(List1.hwnd, LB_RESETCONTENT, 0, 0)
Call SendMessageStr(List1.hwnd, LB_DIR, DDL_FLAGS, ByVal searchPath)
Label1 = r + 1 & " " & Command1(Index).Caption & " found."
End Sub
''--end block--
-------------------------------------------------------------------
By changing the value of the DDL_FLAGS parameter to include or exclude specific DDL_ constants, you determine the type of file structure to include into the list.
For an explanation of my usage of SendMessageLong and SendMessageStr, see Using the Windows SendMessage API Successfully in the Resource Centre.
Tags:
作者:佚名评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论