#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GUIImageList.au3>
#include <GUITreeView.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
Global Const $sRoot = @DesktopDir
$hForm = GUICreate('MyGUI', 600, 600)
GUICtrlCreateTreeView(20, 20, 560, 560, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$hTreeView = GUICtrlGetHandle(-1)
; Windows Vista/7
DllCall('uxtheme.dll', 'uint', 'SetWindowTheme', 'hwnd', $hTreeView, 'wstr', 'Explorer', 'ptr', 0)
$hImageList = _GUIImageList_Create(16, 16, 5, 1)
_GUIImageList_AddIcon($hImageList, @SystemDir & '\shell32.dll', 3)
_GUIImageList_AddIcon($hImageList, @SystemDir & '\shell32.dll', 4)
_GUIImageList_AddIcon($hImageList, @SystemDir & '\shell32.dll', 0)
_GUICtrlTreeView_SetNormalImageList($hTreeView, $hImageList)
_GUICtrlTreeView_BeginUpdate($hTreeView)
_GUICtrlTreeView_EnumDir($hTreeView, $sRoot)
_GUICtrlTreeView_SetState($hTreeView, _GUICtrlTreeView_GetFirstItem($hTreeView), $TVIS_EXPANDED, 1)
_GUICtrlTreeView_EndUpdate($hTreeView)
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func _FileGetIcon($sFile, $iFixIconID = 1)
Local $iOld_Opt_EES = Opt("ExpandEnvStrings", 1)
Local $sRegDefault = "", $sDefIcon = "", $sExecutable, $sExt, $a_LinkInfo, $s_TargetFile, $s_IconFile, $hSearch, $sIconFile
Local $nIcon = 0, $iError = 0, $aRet[3]
If StringInStr(FileGetAttrib($sFile & "\"), "D") Then
$sRegDefault = RegRead("HKCR\Folder", "")
If $sRegDefault <> "" Then
$sDefIcon = RegRead("HKCR\Folder\DefaultIcon", "")
EndIf
Else
$sExt = StringRegExpReplace($sFile, '^.*\.', '.')
If $sExt = ".exe" And FileExists($sFile) Then
Opt("ExpandEnvStrings", $iOld_Opt_EES)
If _WinAPI_ExtractIconEx($sFile, 0, 0, 0, 1) = 0 Then
$sFile = @SystemDir & '\shell32.dll'
$nIcon = -3
EndIf
If $iFixIconID Then
$nIcon = -($nIcon + ($nIcon > 0))
EndIf
Dim $aRet[3] = [2, $sFile, $nIcon]
Return $aRet
EndIf
If $sExt = ".lnk" Then
$aLinkInfo = FileGetShortcut($sFile)
If Not @error Then
$s_TargetFile = $aLinkInfo[0]
$s_IconFile = $aLinkInfo[4]
Opt("ExpandEnvStrings", $iOld_Opt_EES)
If Not FileExists($s_IconFile) Then
$a_LinkInfo = _FileGetIcon($s_TargetFile, 0)
If Not @error Then
$aLinkInfo[4] = $a_LinkInfo[1]
$aLinkInfo[5] = $a_LinkInfo[2]
EndIf
EndIf
If $iFixIconID Then
$aLinkInfo[5] = -($aLinkInfo[5] + ($aLinkInfo[5] > 0))
EndIf
Dim $aRet[3] = [2, $aLinkInfo[4], $aLinkInfo[5]]
Return $aRet
EndIf
EndIf
If $sExt = $sFile Then
$hSearch = FileFindFirstFile($sFile & ".*")
$sExt = StringRegExpReplace(FileFindNextFile($hSearch), '^.*\.', '.')
$sFile &= $sExt
FileClose($hSearch)
EndIf
$sRegDefault = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & $sExt, "ProgID")
If $sRegDefault = "" Then
$sRegDefault = RegRead("HKCR\" & $sExt, "")
EndIf
If $sRegDefault <> "" Then
$sDefIcon = RegRead("HKCR\" & $sRegDefault & "\DefaultIcon", "")
If $sDefIcon = "" Then
$sDefIcon = RegRead("HKCR\" & $sExt & "\DefaultIcon", "")
EndIf
Else
$sRegDefault = RegRead("HKCR\" & $sExt, "PerceivedType")
If $sRegDefault <> "" Then
$sRegDefault = RegRead("HKCR\SystemFileAssociations\" & $sRegDefault & "\DefaultIcon", "")
EndIf
EndIf
EndIf
If $sDefIcon = "" And $sRegDefault <> "" Then
$sDefIcon = RegRead("HKCR\" & $sRegDefault & "\CurVer", "") ; ADOBE PERVERSION....
If $sDefIcon Then
$sDefIcon = RegRead("HKCR\" & $sDefIcon & "\DefaultIcon", "")
Else
$sDefIcon = RegRead("HKCR\" & $sRegDefault & "\shell\open\command", "")
$sDefIcon = StringReplace($sDefIcon, ' "%1"', '')
EndIf
EndIf
If $sDefIcon = "" Then
$sIconFile = @SystemDir & "\shell32.dll"
ElseIf Not StringRegExp($sDefIcon, '\A"*%1"*\z') Then
If StringRegExpReplace($sFile, "^.*\\", "") = "shell32.dll" Then
$sIconFile = $sFile
$nIcon = 0
Else
Local $aDefIconSplit = StringSplit($sDefIcon, ",")
If IsArray($aDefIconSplit) Then
$sIconFile = $aDefIconSplit[1]
If $aDefIconSplit[0] > 1 Then
$nIcon = $aDefIconSplit[2]
EndIf
Else
$iError = 1
EndIf
EndIf
Else
$sIconFile = -1 ;$sFile
$nIcon = 0
EndIf
If Not FileExists($sIconFile) And Not FileExists(@SystemDir & "\" & $sIconFile) Then
$sExecutable = _WinAPI_FindExecutable($sFile)
If FileExists($sExecutable) Then
$sIconFile = $sExecutable
Else
$sExecutable = _WinAPI_PathFindOnPath($sIconFile)
If FileExists($sExecutable) Then
$sIconFile = $sExecutable
EndIf
EndIf
ElseIf FileExists(@SystemDir & "\" & $sIconFile) Then
$sIconFile = @SystemDir & "\" & $sIconFile
EndIf
Opt("ExpandEnvStrings", $iOld_Opt_EES)
If $iFixIconID Then
$nIcon = -($nIcon + ($nIcon > 0))
EndIf
If Not FileExists($sIconFile) Then
$iError = 1
EndIf
Dim $aRet[3] = [2, StringRegExpReplace($sIconFile, '\A"+|"+\z', ''), $nIcon]
Return SetError($iError, 0, $aRet)
EndFunc ;==>_FileGetIcon
Func _GUICtrlTreeView_EnumDir($hWnd, $sRoot, $hItem = 0)
Local $hSubItem, $sItem, $aList
$sRoot = StringRegExpReplace($sRoot, '\\+\Z', '')
$sItem = StringRegExpReplace($sRoot, '^.*\\', '')
If StringRight($sItem, 1) = ':' Then
$sItem &= '\'
EndIf
$hSubItem = _GUICtrlTreeView_AddChild($hWnd, $hItem, $sItem, 0, 1)
$aList = _FileListToArray($sRoot, '*', 2)
If Not @error Then
For $i = 1 To $aList[0]
_GUICtrlTreeView_EnumDir($hWnd, $sRoot & '\' & $aList[$i], $hSubItem)
Next
EndIf
; Если нужен список файлов
$aList = _FileListToArray($sRoot, '*', 1)
If Not @error Then
For $i = 1 To $aList[0]
$aIcon = _FileGetIcon($sRoot & '\' & $aList[$i], 0)
If Not @error Then
$iIcon = _GUIImageList_AddIcon($hImageList, $aIcon[1], $aIcon[2])
Else
$iIcon = 2
EndIf
_GUICtrlTreeView_AddChild($hWnd, $hSubItem, $aList[$i], $iIcon, $iIcon)
Next
EndIf
EndFunc ;==>_GUICtrlTreeView_EnumDir
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $tNMTREEVIEW = DllStructCreate($tagNMTREEVIEW, $lParam)
Local $hTV = DllStructGetData($tNMTREEVIEW, 'hWndFrom')
Local $ID = DllStructGetData($tNMTREEVIEW, 'Code')
Switch $hTV
Case $hTreeView
Switch $ID
Case $TVN_ITEMEXPANDEDA, $TVN_ITEMEXPANDEDW
_GUICtrlTreeView_SetImageIndex($hTreeView, _
DllStructGetData($tNMTREEVIEW, 'NewhItem'), _
BitAND(DllStructGetData($tNMTREEVIEW, 'NewState'), $TVIS_EXPANDED) = $TVIS_EXPANDED)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY