This
routine demonstrates using SendMessage to populate a combo box with any combination of files, directories and drives. Although this
demo uses the wildcard *.*, the method is valid for any mask.
Note 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 end up with the needed control over the display of files.
The added bonus is that this method is that it's instantaneous. |
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const CB_DIR = &H145
Private Const CB_RESETCONTENT = &H14B
Private Const DDL_READWRITE = &H0
Private Const DDL_READONLY = &H1
Private Const DDL_HIDDEN = &H2
Private Const DDL_SYSTEM = &H4
Private Const DDL_DIRECTORY = &H10
Private Const DDL_ARCHIVE = &H20
Private Const DDL_DRIVES = &H4000
Private Const DDL_EXCLUSIVE = &H8000&
Private Const DDL_POSTMSGS = &H2000
Private Const DDL_FLAGS = DDL_ARCHIVE Or DDL_DIRECTORY
Private Sub Form_Load()
Command1(0).Caption = "normal files"
Command1(1).Caption = "normal files and folders"
Command1(2).Caption = "hidden files"
Command1(3).Caption = "system files"
Command1(4).Caption = "folders"
Command1(5).Caption = "drives"
End Sub
Private Sub Command1_Click(Index As Integer)
Dim numfound As Long
Dim DDL_FLAGS As Long
Dim searchPath As String
searchPath = "c:\winnt\*.*"
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 combo
Call SendMessage(Combo1.hwnd, CB_RESETCONTENT, 0&, ByVal 0&)
numfound = SendMessage(Combo1.hwnd, CB_DIR, DDL_FLAGS, ByVal searchPath)
Label1.Caption = numfound + 1 & " " & Command1(Index).Caption & " found."
End Sub
|