jbsmith20 Posted August 9, 2012 Posted August 9, 2012 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 expandcollapse popup#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
LarsJ Posted August 9, 2012 Posted August 9, 2012 Hi jbsmith20,It is not a trivial task to find the right icon for a file. Take a look at the post in the link and I think you can copy the code you need. http://www.autoitscript.com/forum/index.php?showtopic=139026LarsJ Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
jbsmith20 Posted August 18, 2012 Author Posted August 18, 2012 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 expandcollapse popuplocal $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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now