This
routine demonstrated using the API and a standard listbox to duplicate the functionality of a FileList Box. By using this method over
the FileListBox, you can control the files, directories and drives displayed.
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. |
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 LB_DIR = &H18D
Private Const LB_RESETCONTENT = &H184
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 found As Long
Dim DDL_FLAGS As Long
Dim sPath As String
sPath = "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 listbox
Call SendMessage(List1.hwnd, LB_RESETCONTENT, 0, ByVal 0)
found = SendMessage(List1.hwnd, LB_DIR, DDL_FLAGS, ByVal sPath)
Label1.Caption = found + 1 & " " & Command1(Index).Caption & " found."
End Sub |