Sign in to follow this  
Followers 0
jbsmith20

Problems with exe icon to imagelist to correct listview item

3 posts in this topic

Trying make a file/folder browser and after hours going into day of testing / searching, stoping and starting the project over a number of weeks I have found that I can not get it myself

The Problem: Getting icons from a list of mixed files (.lnk, .exe, .png.....some of the .link files are actualy folders) adding them to a imagelist then settings the correct icon with the list of files/folders in a listview

Im new with AutoIt but have made similar and more advanced applications in vb.net

The Code Below is a #include file in my main app (The file name is LVAdd_Files_Folders.au3)

and I made it just so everything wasnt so clustered

#include-once
local $ico,$Icons,$imglist,$tIcon


Func _LVAdd_Files_Folders()
$FileList = _FileListToArray($directory, '*.*', 1) ; File Directory
$FolderList = _FileListToArray($directory, '*.*', 2) ;Only folders
; Add items

; Load File
$imglist = _GUIImageList_Create(32, 32)
For $n = 1 To UBound($FileList) - 1
$File_Name = $FileList[$n]

if StringInStr($File_Name,".lnk",2) then
$tIcon = FileGetShortcut($directory & $File_Name)

if not @error then _GUIimagelist_AddIcon($imglist,$tIcon[0],$tIcon[5])
_GUICtrlListView_AddItem($ListView1, $File_Name,_GUIImageList_GetImageCount($imglist))
Elseif StringInstr($File_Name,".txt",2) or StringInStr($File_Name,".doc",2) Then
_GUIimagelist_AddIcon($imglist, "shell32.dll", 71)
_GUICtrlListView_AddItem($ListView1, $File_Name,_GUIImageList_GetImageCount($imglist))

Else
_GUIimagelist_AddIcon($imglist,$directory & $File_Name,0)
_GUICtrlListView_AddItem($ListView1, $File_Name,_GUIImageList_GetImageCount($imglist))
endif

Next

;Add Folders
For $i = 1 To UBound($FolderList) - 1
$Folder_Name = $FolderList[$i]
if StringInStr($Folder_Name,$Folder_Name,2) Then
_GUIimagelist_AddIcon($imglist, "shell32.dll", 4)
_GUICtrlListView_AddItem($ListView1, $Folder_Name,_GUIImageList_GetImageCount($imglist))

endif
Next
_GUICtrlListView_SetImageList($listview1, $imglist,1)
EndFunc ;==>_LVAdd_Files_Folders

Thanks in Advance to anyone who can help

Share this post


Link to post
Share on other sites



Share this post


Link to post
Share on other sites

Thanks I looked over it and it seems like it would work for what im trying to do but while I was waiting for a reply I messed around with my code and got something working so i might mess with it a little more before I go and modify it too much, at least i know a way to get the proper default icon for the files with the exception of files that get there icons from dlls and from a files default programs still working on that part, thought of trying some registry reading to get default programs but i haven't gotten to it yet

Thanks Again

local $tIcon, $imgcount, $sfile

Func _LVAdd_Files()
$FileList=_FileListToArray($directory,'*.*', 1) ; Files Only
; Add items

; Load File
$hImage = _GUIImageList_Create(32, 32)
_GUIImageList_AddIcon($hImage,"viewerdll.dll",0)

_guictrllistview_additem($listview1,"",_GUIImageList_GetImageCount($hImage)-1)
_GUIImageList_AddIcon($hImage,"explorer.exe",0)
_guictrllistview_additem($listview1,"Computer",_GUIImageList_GetImageCount($hImage)-1)
For $n = 1 to UBound($FileList)-1
$File_Name = $FileList[$n]

If StringInstr($File_Name,".Lnk",2) Then
$tIcon = FileGetShortcut($directory & $File_Name)
if FileGetSize($tIcon[0]) = 0 Then
_GUIImageList_AddIcon($hImage,"Shell32.dll",4)
_GUICtrlListView_AddItem($listview1, $File_Name,_GUIImageList_GetImageCount($hImage)-1)
if @error Then
msgbox(0,"Error","Error Must Restart")
EndIf

EndIf

if FileGetSize($tIcon[0]) > 1 Then
_GUIImageList_AddIcon($hImage,$tIcon[0],0)
_GUICtrlListView_AddItem($listview1, $File_Name,_GUIImageList_GetImageCount($hImage)-1)

elseif @error then
_GUIImageList_AddIcon($hImage,"Shell32.dll",0)
_GUICtrlListView_AddItem($listview1, $File_Name,_GUIImageList_GetImageCount($hImage)-1)


EndIf
EndIf


If not StringInstr($File_Name,".lnk",2) Then
$sfile = FileGetShortcut($directory & $File_Name)
If StringInstr($File_Name,".bat",2) Then
_GUIImageList_AddIcon($hImage,"Shell32.dll",71)
_GUICtrlListView_AddItem($listview1, $File_Name,_GUIImageList_GetImageCount($hImage)-1)
EndIf
If StringInstr($File_Name,".png",2) Then
_GUIImageList_Addicon($hImage,"imageres.dll",78)
_GUICtrlListView_AddItem($listview1, $File_Name,_GUIImageList_GetImageCount($hImage)-1)

EndIf
If StringInstr($File_Name,".bmp",2) Then
_GUIImageList_Addicon($hImage,$directory & $File_Name)
_GUICtrlListView_AddItem($listview1, $File_Name,_GUIImageList_GetImageCount($hImage)-1)
EndIf

if StringInstr($File_Name,".bin",2) Then

_GUIImageList_AddIcon($hImage,"viewerdll.dll",0)
_GUICtrlListView_AddItem($listview1, $File_Name,_GUIImageList_GetImageCount($hImage)-1)

EndIf

if StringInstr($File_Name,".exe",2) Then
_GUIImageList_AddIcon($hImage,$directory & $File_Name)
_GUICtrlListView_AddItem($listview1, $File_Name,_GUIImageList_GetImageCount($hImage)-1)

EndIf


Else


if not StringInstr($File_Name,".lnk",2) Then
if not StringInstr($File_Name,".bat",2) Then
if not StringInstr($File_Name,"png",2) Then
if not StringInstr($File_Name,".bmp",2) Then
if not StringInstr($File_Name,".bin",2) Then
if not StringInstr($File_Name,".exe",2) Then
_GUIImageList_AddIcon($hImage,"viewerdll.dll",0)
_GUICtrlListView_AddItem($listview1, $File_Name,_GUIImageList_GetImageCount($hImage)-1)

EndIf
EndIf
EndIf
EndIf
EndIf
EndIf



EndIf
Next




_GUICtrlListView_SetImageList($listview1, $hImage,1)

endfunc

Func _LVAdd_Folders()
$FolderList=_FileListToArray($directory,'*.*', 2) ;Only folders

;Add Folders
for $i = 1 to UBound($FolderList)-1
$Folder_Name = $FolderList[$i]
_GUIImageList_AddIcon($hImage,"Shell32.dll",4)
_GUICtrlListView_AddItem($ListView1,$Folder_Name,_GUIImageList_GetImageCount($hImage)-1)

next
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0