Page 1 sur 1

Le chemin des répertoires spéciaux

MessagePublié: 05 Nov 2007 à 17:55
par Michael DELIQUE
Code : Tout sélectionner
Public Function GetSpecialFolder_API(CSIDL As Long) As String
   
%REM
'Variables API pour la fonction GetSpecialFolder_API
Private Type SHITEMID
   nbcb As Long
   abID As Single
End Type
Private Type ITEMIDLIST
   mkid As SHITEMID
End Type
Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (Byval hwndOwner As Long, Byval nFolder As Long, pidl As ITEMIDLIST) As Long
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (Byval pidl As Long, Byval pszPath As String) As Long
Const CSIDL_DESKTOP = &H0
Const CSIDL_PROGRAMS = &H2
Const CSIDL_CONTROLS = &H3
Const CSIDL_PRINTERS = &H4
Const CSIDL_PERSONAL = &H5
Const CSIDL_FAVORITES = &H6
Const CSIDL_STARTUP = &H7
Const CSIDL_RECENT = &H8
Const CSIDL_SENDTO = &H9
Const CSIDL_BITBUCKET = &HA
Const CSIDL_STARTMENU = &HB
Const CSIDL_DESKTOPDIRECTORY = &H10
Const CSIDL_DRIVES = &H11
Const CSIDL_NETWORK = &H12
Const CSIDL_NETHOOD = &H13
Const CSIDL_FONTS = &H14
Const CSIDL_TEMPLATES = &H15
%END REM
   
   
   'Daclaration Variable
   Dim Path As String
   Dim i As Long
   Dim IDL As ITEMIDLIST
   
   On Error Goto ErreurGetSpecialFolder_API
   
'Get the special folder
   i = SHGetSpecialFolderLocation(100, CSIDL, IDL)
   
   If i = 0 Then
'Create a buffer
      Path = Space(512)
'Get the path from the IDList
      i = SHGetPathFromIDList(Byval IDL.mkid.nbcb, Byval Path)
'Remove the unnecessary chr$(0)'s
      GetSpecialfolder_API = Left(Path, Instr(Path, Chr(0)) - 1)
      Exit Function
   End If
   GetSpecialfolder_API = ""
   
   
   'Appel de la fonction :
   'dim text as string
   ' text = GetSpecialFolder(CSIDL_DESKTOP )
   Exit Function
ErreurGetSpecialFolder_API:
   Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
   GetSpecialfolder_API = ""
   Exit Function   
End Function