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
| ' DECLARATION DES FONCTIONS API DE SPECIALS FOLDER
'Déclaration en 64 ou 32 bits
#If VBA7 Then
Private Declare PtrSafe Function SHGetPathFromIDList _
Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" ( _
ByVal pidl As LongPtr, _
ByVal pszPath As String) _
As Boolean
Private Declare PtrSafe Function SHGetSpecialFolderLocation _
Lib "shell32.dll" ( _
ByVal hwndOwner As LongPtr, _
ByVal nFolder As Long, _
pidl As ITEMIDLIST) _
As LongPtr
Private Type SHITEMID
SHItem As LongPtr
itemID() As Byte
End Type
#Else
Private Declare Function SHGetPathFromIDList _
Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" ( _
ByVal pidl As Long, _
ByVal pszPath As String) _
As Boolean
Private Declare Function SHGetSpecialFolderLocation _
Lib "shell32" ( _
ByVal hwndOwner As Long, _
ByVal nFolder As Long, _
shidl As ITEMIDLIST) _
As Long
Private Type SHITEMID
SHItem As Long
itemID() As Byte
End Type
#End If
Private Type ITEMIDLIST
shellID As SHITEMID
End Type
' ENUMS POUR SPECIALS FOLDERS
Public Enum vaDossier
ApplicationDatas = 26
Bureau = 16
BureauCommun = 25
Cookies = 33
Demarrer = 11
DemarrerCommun = 22
DemarrerDemarrage = 7
DemarrerDemarrageCommun = 24
DemarrerMenuDemarrer = 29
DemarrerProgrammes = 2
DemarrerProgrammesCommun = 23
Documents = 5
DocumentsCommuns = 46
DocumentsRecents = 8
DossierLocal = 28
EnvoyerVers = 9
Favoris = 6
FavorisCommuns = 1
FichierInternetTemporaires = 32
Historique = 34
Images = 39
ImagesPubliques = 54
MesFavories = 31
Modeles = 21
MusiquePublique = 53
Musiques = 13
Polices = 20
ProgrammeData = 35
Programmes = 38
RaccourcisImprimantes = 27
RaccourcisReseau = 19
Utilisateur = 40
Videos = 14
VideosPubliques = 55
Windows = 36
WindowsSysteme = 37
WindowsSYSWOW = 41
WindowsTemplates = 45
End Enum
'@Description "Retourne le chemin d'un dossier spécial windows"
Public Function getSpecialFolderPath(ByVal SpecialFolder As vaDossier) As String
Dim localPath As String
Dim dtuID As ITEMIDLIST
#If VBA7 Then
Dim lngRes As LongPtr
#Else
Dim lngRes As Long
#End If
' // Chercher le Bureau virtuel.
lngRes = SHGetSpecialFolderLocation(0&, SpecialFolder, dtuID)
If lngRes = 0 Then ' Pas d'erreur...
localPath = String$(512, Chr$(0))
lngRes = SHGetPathFromIDList(dtuID.shellID.SHItem, localPath)
If lngRes Then getSpecialFolderPath = Left$(localPath, _
InStr(localPath, Chr$(0)) - 1)
End If
End Function |
Partager