Page 1 sur 1

[R] Icone de fichier dans un TreeView

Posté : dim. 04 oct. 2009 23:06
par L4crymal
Bonjour, je fais en ce moment un script qui répertorie tous les fichiers d'un dossier puis les affiche dans un TreeView.

Et j'aimerai que chaque nom de fichier est son icône en face.


Merci de votre aide.

Re: [..] Icone de fichier dans un TreeView

Posté : lun. 05 oct. 2009 00:53
par Iste
a l'aide du fameux <FileListToArray3.au3> et de ce topic, voici ;)

Code : Tout sélectionner

#include <GUIListView.au3>
#include <Constants.au3>
#include<FileListToArray3.au3>


Global $GUI_MAIN = GUICreate("Au3FTP", 500, 200)
Global $ListView1 = GUICtrlCreateListView("Name                                     ",0,0,500,200)
Global $hListView1= GUICtrlGetHandle($ListView1)
_GUICtrlListView_SetImageList($ListView1, _GUIImageList_GetSystemImageList(), 1)

$ar_Array = _FileListToArray3 ("C:\Documents and Settings\Iste\Bureau", "*", 1)
_ArrayDelete($ar_Array,0)
For $i = 0 To UBound($ar_Array) -1
_GUICtrlListView_AddItem($hListView1, $ar_Array[$i], _GUIImageList_GetFileIconIndex($ar_Array[$i]))
Next

GUISetState(@SW_SHOW)

While True
    Sleep(100)
WEnd

Func _GUIImageList_GetSystemImageList()

    Local $FileInfo = DllStructCreate('dword hIcon; int iIcon; DWORD dwAttributes; CHAR szDisplayName[255]; CHAR szTypeName[80];')
    Local $uFlags = BitOR(0x10, 0x4000, 0x1)
    Local $hImageList = _WinAPI_SHGetFileInfo( ".txt", _
                                        0x80, _
                                        DllStructGetPtr($FileInfo), DllStructGetSize($FileInfo), _
                                        $uFlags )
    Return $hImageList
EndFunc

Func _GUIImageList_GetFileIconIndex($sFileSpec)

    Local $FileInfo = DllStructCreate('dword hIcon; int iIcon; DWORD dwAttributes; CHAR szDisplayName[255]; CHAR szTypeName[80];')
    Local $uFlags = BitOR(0x4000,0x10,0x1)
    Local $hImageList = _WinAPI_SHGetFileInfo( $sFileSpec, _
                                        $FILE_ATTRIBUTE_NORMAL, _
                                        DllStructGetPtr($FileInfo), DllStructGetSize($FileInfo), _
                                        $uFlags )

    Return DllStructGetData($FileInfo, "iIcon")

EndFunc

Func _WinAPI_SHGetFileInfo($pszPath, $dwFileAttributes, $psfi, $cbFileInfo, $uFlags)
    Local $return = DllCall( "shell32.dll", "DWORD*", "SHGetFileInfo", _
                             "str", $pszPath, "DWORD", $dwFileAttributes, _
                             "ptr", $psfi, "UINT", $cbFileInfo, _
                             "UINT", $uFlags )
    If @error Then Return SetError(@error, 0, 0)
    Return $return[0]
EndFunc
 

Re: [..] Icone de fichier dans un TreeView

Posté : lun. 05 oct. 2009 18:14
par L4crymal
Ow merci ^^