Dann erstelle die ListView mit GUICtrlCreateListView und damit du die erweiterten Funktionen der GuiListView.au3 (welche ja ein Handle erwarten) verwenden kannst ermittelst du einmal das Handle mit
. Dieses verwendest du im weiteren Programm.
Edit: ich weis nicht mit welcher AutoIt-Version es eingeführt wurde, aber zumindest mit 3.3.14.1 funktioniert es auch über die ControlID, siehe:
Spoiler anzeigen
C
#include <APIShellExConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <File.au3>
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
Global Const $tagSHFILEINFO = 'ptr hIcon; int iIcon; DWORD dwAttributes; CHAR szDisplayName[255]; CHAR szTypeName[80];'
Global $FOLDER_ICON_INDEX= _GUIImageList_GetFileIconIndex(@SystemDir, True, 1)
;Global $UP_ICON_INDEX = _GUIImageList_GetFileIconIndex($sIconDir & 'up.ico', False, 1)
Global $sAutoItPath = RegRead64('HKLM\Software\AutoIt v3\AutoIt', 'InstallDir')
Global $aDirs, $aFiles
; Create GUI
Global $hGui = GUICreate("ListView Add Item", 500, 700,Default,Default,$LVS_SHOWSELALWAYS)
GUISetFont(14)
Global $idListview = GUICtrlCreateListView("Name:", 2, 2, 494, 694,$LVS_SHOWSELALWAYS)
_GUICtrlListView_SetImageList($idListview, _GUIImageList_GetSystemImageList(True), 1)
GUISetState(@SW_SHOW)
If @error Then
$sAutoItPath=''
if MsgBox(16,'Ordner nicht gefunden','Möchten Sie selbst danach suchen?',$MB_YESNO,$hGui)=6 Then
$sAutoItPath=FileSelectFolder('AutoIt Ordner manuell suchen','c:\')&'\'
EndIf
if $sAutoItPath='' Then Exit
EndIf
_GUICtrlListView_BeginUpdate($idListview)
$sAutoItPath='C:\Program Files\Microsoft Office 15\root\office15\' ;dieser Pfad hat mehr Files mit individuellen Icons
$aDirs = _FileListToArray($sAutoItPath, '*', 2)
If Not @error Then
For $i = 1 To $aDirs[0]
; Add items
_GUICtrlListView_AddItem($idListview, $aDirs[$i], $FOLDER_ICON_INDEX, True)
Next
EndIf
$aFiles = _FileListToArray($sAutoItPath, '*', 1)
If Not @error Then
For $i = 1 To $aFiles[0]
; Add items
_GUICtrlListView_AddItem($idListview, $aFiles[$i], _GUIImageList_GetFileIconIndex($sAutoItPath&$aFiles[$i], True))
Next
EndIf
_GUICtrlListView_SetColumnWidth($idListview,0,$LVSCW_AUTOSIZE)
_GUICtrlListView_EndUpdate($idListview)
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
; Author: progandy (www.autoit.de)
Func _GUIImageList_GetSystemImageList($bLargeIcons = False)
Local $dwFlags, $hIml, $FileInfo = DllStructCreate($tagSHFILEINFO)
$dwFlags = BitOR($SHGFI_USEFILEATTRIBUTES, $SHGFI_SYSICONINDEX)
If Not ($bLargeIcons) Then
$dwFlags = BitOR($dwFlags, $SHGFI_SMALLICON)
EndIf
;~ '// Load the image list - use an arbitrary file extension for the
;~ '// call to SHGetFileInfo (we don't want to touch the disk, so use
;~ '// FILE_ATTRIBUTE_NORMAL && SHGFI_USEFILEATTRIBUTES).
$hIml = _WinAPI_SHGetFileInfo(".txt", $FILE_ATTRIBUTE_NORMAL, _
DllStructGetPtr($FileInfo), DllStructGetSize($FileInfo), $dwFlags)
Return $hIml
EndFunc ;==>_GUIImageList_GetSystemImageList
; Author: progandy (www.autoit.de)
Func _WinAPI_SHGetFileInfo($pszPath, $dwFileAttributes, $psfi, $cbFileInfo, $uFlags)
Local $return = DllCall("shell32.dll", "dword_ptr", "SHGetFileInfo", "str", $pszPath, "DWORD", $dwFileAttributes, "ptr", $psfi, "UINT", $cbFileInfo, "UINT", $uFlags)
If @error Then Return SetError(@error, 0, 0)
Return $return[0]
EndFunc ;==>_WinAPI_SHGetFileInfo
; Author: progandy (www.autoit.de)
Func _GUIImageList_GetFileIconIndex($sFileSpec, $bLargeIcons = False, $bForceLoadFromDisk = False)
Local $dwFlags, $FileInfo = DllStructCreate($tagSHFILEINFO)
$dwFlags = $SHGFI_SYSICONINDEX
If $bLargeIcons Then
$dwFlags = BitOR($dwFlags, $SHGFI_LARGEICON)
Else
$dwFlags = BitOR($dwFlags, $SHGFI_SMALLICON)
EndIf
;~ ' We choose whether to access the disk or not. If you don't
;~ ' hit the disk, you may get the wrong icon if the icon is
;~ ' not cached. But the speed is very good!
If Not $bForceLoadFromDisk Then $dwFlags = BitOR($dwFlags, $SHGFI_USEFILEATTRIBUTES)
;~ ' sFileSpec can be any file. You can specify a
;~ ' file that does not exist and still get the
;~ ' icon, for example sFileSpec = "C:\PANTS.DOC"
Local $lR = _WinAPI_SHGetFileInfo( _
$sFileSpec, $FILE_ATTRIBUTE_NORMAL, DllStructGetPtr($FileInfo), DllStructGetSize($FileInfo), _
$dwFlags _
)
If ($lR = 0) Then
Return SetError(1, 0, -1)
Else
Return DllStructGetData($FileInfo, "iIcon")
EndIf
EndFunc ;==>_GUIImageList_GetFileIconIndex
Func RegRead64($sKeyname, $sValue);aus AutoUpdateIt.au3
Local $sRes = RegRead($sKeyname, $sValue)
If @error And @AutoItX64 Then
$sKeyname = StringReplace($sKeyname, "HKEY_LOCAL_MACHINE", "HKLM")
$sKeyname = StringReplace($sKeyname, "HKLM\SOFTWARE\", "HKLM\SOFTWARE\Wow6432Node\")
$sRes = RegRead($sKeyname, $sValue)
If @error Then
SetError(1)
Return ""
EndIf
EndIf
SetError(0)
Return $sRes
EndFunc ;==>RegRead64
Alles anzeigen