1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
Option Explicit
Public Const MAX_FILENAME_LEN = 256
Public Declare Function OleCreatePictureIndirect Lib "olepro32.dll" _
(PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Public Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" _
(ByVal pszPath As Any, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, _
ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function FindExecutableA Lib "shell32.dll" _
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Public Type PicBmp
Size As Long
tType As Long
hBmp As Long
hPal As Long
Reserved As Long
End Type
Public Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Public Type SHFILEINFO
hicon As Long
iIcon As Long
dwAttributes As Long
szDisplayName As String * 260
szTypeName As String * 80
End Type
Public Function GetIconFromFile(FileName As String, IconIndex As Long, _
UseLargeIcon As Boolean) As IPicture
'**************************************************************
'Necessite d'activer la reference "Standard OLE Types"
'**************************************************************
Dim b As SHFILEINFO
Dim retval As Long
Dim pic As PicBmp
Dim IPic As IPicture
Dim IID_IDispatch As GUID
retval = SHGetFileInfo(FileName, 0, b, Len(b), &H100)
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
With pic
.Size = Len(b)
.tType = 3 'vbPicTypeIcon
.hBmp = b.hicon
End With
Call OleCreatePictureIndirect(pic, IID_IDispatch, 1, IPic)
Set GetIconFromFile = IPic
End Function
'************************************************************
' Charge les fichiers dans ListView *
'************************************************************
Sub ElementsRepertoire(Chemin As String, LV As Object, IL As Object)
Dim objShell As Object, objFolder As Object, strFileName As Object
Dim x As Integer, nbFichiers As Integer, SecuriteSlash As Integer
Dim Tableau() As String
Dim Direction As String, Executable As String
'**************************************************************************************
On Error Resume Next
' Vide ListView
LV.ListItems.Clear
IL.ListImages.Clear
'lister les fichiers du repertoire
Direction = Dir(Chemin & "\*.*")
Do While Len(Direction) > 0
nbFichiers = nbFichiers + 1
ReDim Preserve Tableau(1 To nbFichiers)
Tableau(nbFichiers) = Direction
Direction = Dir()
Loop
'**************************************************************************************
With IL
.ListImages.Clear
.ImageWidth = 20
.ImageHeight = 20
End With
If nbFichiers > 0 Then
For x = 1 To nbFichiers
Executable = FindExecutable(Chemin & "\" & Tableau(x)) 'cherche l'executable associé au fichier
IL.ListImages.Add , "A" & x, GetIconFromFile(Executable, 0, False) 'recupere le 1er icone
'Debug.Print GetIconFromFile(Executable, 0, False)
Next x
LV.SmallIcons = IL
With LV
With .ColumnHeaders
.Clear
.Add , , "Nom du Fichier", 135
'.Add , , "Taille", 70
.Add , , "Date", 60
'.Add , , "Commentaire", 280
End With
For x = 1 To nbFichiers
.ListItems.Add , , Tableau(x)
'.ListItems(x).ListSubItems.Add , , FileLen(Chemin & "\" & Tableau(x)) '& " octets"
.ListItems(x).ListSubItems.Add , , Format(FileDateTime(Chemin & "\" & Tableau(x)), "DD/MM/YYYY")
.ListItems(x).SmallIcon = "A" & x
Next
End With
End If
End Sub
'trouve quel executable ouvre le fichier cible
Public Function FindExecutable(S As String) As String
Dim I As Integer, S2 As String
S2 = String(MAX_FILENAME_LEN, 32) & Chr$(0)
I = FindExecutableA(S & Chr$(0), vbNullString, S2)
If I > 32 Then
FindExecutable = Left$(S2, InStr(S2, Chr$(0)) - 1)
Else
FindExecutable = ""
End If
End Function |
Partager