|
APIs: Repérer la localisation d'un dossier spécial |
Author(s) Dev Ashish |
|
La nomenclature du Shell de Windows organise tous les objets (spécifiques
ou pas au stockage) du système de fichier en un seul arbre hiérarchique. Il y
a certains répertoires (virtuels) qui sont automatiquement créés et gérés
par le système d'exploitation. Les utilisateurs ne peuvent pas créer de tel
dossiers virtuels.
Pour obtenir le chemin physique qui correspond à ces dossiers virtuels, le
système d'exploitation fournit les fonctions SHGetSpecialFolderLocation et SHGetPathFromIDList.
Pour retrouver les chemins physiques, fournir une valeur de type CSIDL
à la fonction fGetSpecialFolderLocation.
Note: Ce ne sont pas tous les dossiers qui existent
simultanément sous Win 9x et NT/2000. Prière de prendre note du
commentaire précédant chacune des constante pour plus de détails.
Public Const CSIDL_FLAG_CREATE = &H8000
Public Const CSIDL_ADMINTOOLS = &H30
Public Const CSIDL_ALTSTARTUP = &H1D
Public Const CSIDL_APPDATA = &H1A
Public Const CSIDL_BITBUCKET = &HA
Public Const CSIDL_COMMON_ADMINTOOLS = &H2F
Public Const CSIDL_COMMON_ALTSTARTUP = &H1E
Public Const CSIDL_COMMON_APPDATA = &H23
Public Const CSIDL_COMMON_DESKTOPDIRECTORY = &H19
Public Const CSIDL_COMMON_DOCUMENTS = &H2E
Public Const CSIDL_COMMON_FAVORITES = &H1F
Public Const CSIDL_COMMON_PROGRAMS = &H17
Public Const CSIDL_COMMON_STARTMENU = &H16
Public Const CSIDL_COMMON_STARTUP = &H18
Public Const CSIDL_COMMON_TEMPLATES = &H2D
Public Const CSIDL_CONTROLS = &H3
Public Const CSIDL_COOKIES = &H21
.
Public Const CSIDL_DESKTOP = &H0
Public Const CSIDL_DESKTOPDIRECTORY = &H10
Public Const CSIDL_DRIVES = &H11
Public Const CSIDL_FAVORITES = &H6
Public Const CSIDL_FONTS = &H14
Public Const CSIDL_HISTORY = &H22
Public Const CSIDL_INTERNET = &H1
Public Const CSIDL_INTERNET_CACHE = &H20
Public Const CSIDL_LOCAL_APPDATA = &H1C
Public Const CSIDL_MYPICTURES = &H27
Public Const CSIDL_NETHOOD = &H13
Public Const CSIDL_NETWORK = &H12
Public Const CSIDL_PERSONAL = &H5
Public Const CSIDL_PRINTERS = &H4
Public Const CSIDL_PRINTHOOD = &H1B
Public Const CSIDL_PROFILE = &H28
Public Const CSIDL_PROGRAM_FILES = &H2A
Public Const CSIDL_PROGRAM_FILES_COMMON = &H2B
Public Const CSIDL_PROGRAM_FILES_COMMONX86 = &H2C
Public Const CSIDL_PROGRAM_FILESX86 = &H2A
Public Const CSIDL_PROGRAMS = &H2
Public Const CSIDL_RECENT = &H8
Public Const CSIDL_SENDTO = &H9
Public Const CSIDL_STARTMENU = &HB
Public Const CSIDL_STARTUP = &H7
Public Const CSIDL_SYSTEM = &H25
Public Const CSIDL_SYSTEMX86 = &H29
Public Const CSIDL_TEMPLATES = &H15
Public Const CSIDL_WINDOWS = &H24
Public Const NOERROR = 0
Private Declare Function apiSHGetSpecialFolderLocation Lib "shell32" _
Alias "SHGetSpecialFolderLocation" _
(ByVal hwndOwner As Long, _
ByVal nFolder As Long, _
ppidl As Long) _
As Long
Private Declare Function apiSHGetPathFromIDList Lib "shell32" _
Alias "SHGetPathFromIDList" _
(pidl As Long, _
ByVal pszPath As String) _
As Long
Private Declare Sub sapiCoTaskMemFree Lib "ole32" _
Alias "CoTaskMemFree" _
(ByVal pv As Long)
Private Const MAX_PATH = 260
Function fGetSpecialFolderLocation(ByVal lngCSIDL As Long) As String
Dim lngRet As Long
Dim strLocation As String
Dim pidl As Long
lngRet = apiSHGetSpecialFolderLocation(hWndAccessApp, lngCSIDL, pidl)
If lngRet = NOERROR Then
strLocation = Space$(MAX_PATH)
lngRet = apiSHGetPathFromIDList(ByVal pidl, strLocation)
If Not lngRet = 0 Then
fGetSpecialFolderLocation = Left$(strLocation, _
InStr(strLocation, vbNullChar) - 1)
End If
Call sapiCoTaskMemFree(pidl)
End If
End Function
|