2. If there is a comma in the path to the icon, the path parser will not work. But I don't want to complicate the code.
3. Any ideas to improve the code?
Code: Select all
EnableExplicit
#ASSOCSTR_DEFAULTICON = 15
#ASSOCF_NONE = 0
Structure Icons
Ext.s
hIcon.i
EndStructure
Define NewList FilesLst.s()
Define NewList IconsLst.Icons()
Define LenStr = #MAX_PATH
Define AssIcon$ = Space(LenStr)
Define tmp$, Pos, hIcon
Define path.String, Ext$, isNotFind = 1
path\s = Space(#MAX_PATH)
ExtractIconEx_("Shell32.dll", 0, 0, @hIcon, 1)
AddElement(IconsLst())
IconsLst()\hIcon = hIcon
IconsLst()\Ext = ""
Define Count, a
#Tree = 0
#btn = 1
AddElement(FilesLst())
FilesLst() = "image.gif"
AddElement(FilesLst())
FilesLst() = "image.gif"
AddElement(FilesLst())
FilesLst() = "image.png"
AddElement(FilesLst())
FilesLst() = "Text.txt"
AddElement(FilesLst())
FilesLst() = "Text.txt"
AddElement(FilesLst())
FilesLst() = "image.gif"
AddElement(FilesLst())
FilesLst() = "image.iso"
AddElement(FilesLst())
FilesLst() = "help.chm"
AddElement(FilesLst())
FilesLst() = "m.mp3"
If OpenWindow(0, 0, 0, 355, 300, "Tree", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TreeGadget(#Tree, 10, 10, 260, 280, #PB_Tree_CheckBoxes | #PB_Tree_NoLines)
ButtonGadget(#btn, 280, 10, 30, 30, "v")
ForEach FilesLst()
isNotFind = 1
Ext$ = GetExtensionPart(FilesLst())
ForEach IconsLst()
If IconsLst()\Ext = Ext$
isNotFind = 0
Break
EndIf
Next
If isNotFind
tmp$ = "." + Ext$
If AssocQueryString_(#ASSOCF_NONE, #ASSOCSTR_DEFAULTICON, @tmp$, #Null$, @AssIcon$, @LenStr) = #S_OK
PokeS(@path\s, StringField(AssIcon$, 1, ","))
PathFindOnPath_(@path\s, #Null)
If FileSize(path\s) > 0 And AddElement(IconsLst())
ExtractIconEx_(path\s, Val(StringField(AssIcon$, 2, ",")), 0, @IconsLst()\hIcon, 1)
IconsLst()\Ext = Ext$
Else
SelectElement(IconsLst(), 0)
EndIf
Else
SelectElement(IconsLst(), 0)
EndIf
EndIf
AddGadgetItem(#Tree, -1, FilesLst(), IconsLst()\hIcon, Pos)
Next
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #btn
Count = CountGadgetItems(#Tree)
For a = Count - 1 To 0 Step -1
If GetGadgetItemState(#Tree, a) & #PB_Tree_Checked
SetGadgetItemText(#Tree, a, "* Delete")
EndIf
Next
EndSelect
Case #PB_Event_CloseWindow
CloseWindow(0)
End
EndSelect
ForEver
EndIf