doing some code to change assigned icons in windows, I have some problems now:
- I'd like to be able to sort certain columns of the list and to see which column is sorted, an icon should display which icon is sorted.
This works if no other icons are in use, so if the line SearchKeys("") in the Main procedure is remarked, my icon (a circle) is seen correctly.
When SearchKeys() is active another icon is displayed. Why?
In small columns, the icon "replaces" the text, can the distance between text and icon be changed? When removing the icon, the text still is not seen...
When changing the icon index ("<" and ">" buttons, only the big icon below is changed, but not the small icons in the list - any ideas?
Thanks for your help!
Michael
Code: Select all
; Define Icons
EnableExplicit
#MaxIcons=1500
#Stepper=200
;Global RegistryFile.s
Global RegistryHandle=0
Global RegistryHundle=0
Global RegistryPath.s
Global RegistryEntry.s=""
Global RegistryEntrySize=#MAX_PATH
Global RegistryValue.s
Global RegistryValueSize
Global RegistryValueType
Global ListeID
Global ListeKopfhoehe
Global Kopfsymbole
Global SortIcon
Global ClearIcon
Global Dummy
Global Summy.s
Global Rechteck.RECT
Global MouseXY.POINT
#LVM_GETHEADER = #LVM_FIRST+31
;RegistryFile="C:\Dokumente und Einstellungen\vo\Desktop\DefaultIcon.reg"
#RegistryFile="DefaultIcon.reg"
#WorkshopFile="DefaultList.reg"
Global Zeile.s
#TopKey=#HKEY_CLASSES_ROOT
Structure IconType
RegistryPath.s
Name.s
IconFile.s
Index.l
Changed.l
EndStructure
Global Dim Icon.IconType(#MaxIcons)
Global Icons
Global Dim RegistryPathlist.s(#MaxIcons)
Global Path
Global Dim SmallIcon(#MaxIcons)
Global Dim LargeIcon(#MaxIcons)
Global Dim Zeiger(#MaxIcons)
Global Entries
#IconBit=1
#PathBit=2
#NameBit=4
#FileBit=8
#IndexBit=16
#IconsBit=32
#LineBit=64
#NrBit=128
#AllBits=$ffff
; EndDefine
; Define Dialog
Enumeration
#Win
#Liste
#Icon
#File
#ButtLoad
#ButtCool
#ButtOk
#ButtNext
#ButtPrev
#ButtGoReg
#ButtExport
#ButtQuit
#Image
EndEnumeration
Enumeration
#IconColumn
#PathColumn
#NameColumn
#FileColumn
#IndexColumn
#LineColumn
#NrColumn
EndEnumeration
#ListHeight=360
; EndDefine
; Define Icons
DataSection
SortIcon:
IncludeBinary "Ring.ico"
ClearIcon:
Data.l $00010000,$10100001,$00010000,$05680008,$00160000,$00280000
Data.l $00100000,$00200000,$00010000,$00000008,$01400000,$00000000
Data.l $00000000,$00000000,$00000000,$EA000000,$454500FF,$00000045
Data.l $CE000000,$C90000FF,$9D0000FF,$B40000FE,$FE9300FF,$FD1300FF
Data.l $FFC700FF,$E50000FF,$FFEB00FF,$000000FF,$FFFF0000,$000000FF
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$00000000,$00000000,$00000000,$00000000,$00000000
Data.l $00000000,$02020000,$02020202,$02020202,$02020202,$02020202
Data.l $02020202,$02020202,$02020202,$02020202,$02020202,$02020202
Data.l $02020202,$02020202,$02020202,$02020202,$02020202,$02020202
Data.l $02020202,$02020202,$02020202,$02020202,$02020202,$02020202
Data.l $02020202,$02020202,$02020202,$02020202,$02020202,$02020202
Data.l $02020202,$02020202,$02020202,$02020202,$02020202,$02020202
Data.l $02020202,$02020202,$02020202,$02020202,$02020202,$02020202
Data.l $02020202,$02020202,$02020202,$02020202,$02020202,$02020202
Data.l $02020202,$02020202,$02020202,$02020202,$02020202,$02020202
Data.l $02020202,$02020202,$02020202,$02020202,$02020202,$02020202
Data.l $02020202,$02020202,$02020202,$02020202,$02020202,$FFFF0202
Data.l $FFFF0202,$FFFF0202,$FFFF0202,$FFFF0202,$FFFF0202,$FFFF0202
Data.l $FFFF0202,$FFFF0202,$FFFF0202,$FFFF0202,$FFFF0202,$FFFF0202
Data.b 2,2,-1,-1,2,2,-1,-1,2,2,-1,-1,2,2
EndDataSection
; EndDefine
Procedure.s EvalEnvironment(s.s)
Protected pos
Protected var.s
If PeekB(@s)='%'
pos=FindString(s,"%",2)
If pos
var=GetEnvironmentVariable(Mid(s,2,pos-2))
If Len(var)
s=var+PeekS(@s+pos)
EndIf
EndIf
EndIf
ProcedureReturn s
EndProcedure
Procedure SplitIconFile(nr,s.s)
Protected k
k=FindString(s,",",1)
If k
Icon(nr)\IconFile=EvalEnvironment(Left(s,k-1))
Icon(nr)\Index=Val(PeekS(@s+k))
Else
Icon(nr)\IconFile=EvalEnvironment(s)
EndIf
EndProcedure
Procedure.l GetKey(Subkey.s)
;Debug "? "+Subkey
If RegOpenKeyEx_(#TopKey,@Subkey,0,#KEY_ALL_ACCESS,@RegistryHundle)=#ERROR_SUCCESS
RegistryValue=Space(RegistryEntrySize)
RegistryValueSize=RegistryEntrySize
If RegQueryValueEx_(RegistryHundle,@RegistryEntry,#Null,@RegistryValueType,@RegistryValue,@RegistryValueSize)=#ERROR_SUCCESS
;Debug "! "+RegistryValue
RegCloseKey_(RegistryHundle)
ProcedureReturn #True
EndIf
EndIf
ProcedureReturn #False
EndProcedure
Procedure.l SearchKeys(Subkey.s)
Protected i,k
Icons=0
Path=0
If RegOpenKeyEx_(#TopKey,@SubKey,0,#KEY_ALL_ACCESS,@RegistryHandle)=#ERROR_SUCCESS
RegistryPath=Space(RegistryEntrySize)
RegistryValueSize=RegistryEntrySize
While (Path<#MaxIcons) And (RegEnumKeyEx_(RegistryHandle,Path,@RegistryPath,@RegistryValueSize,0,0,0,0)=#ERROR_SUCCESS)
Path+1
RegistryPathlist(Path)=RegistryPath
RegistryPath=Space(RegistryEntrySize)
RegistryValueSize=RegistryEntrySize
Wend
i=0
While i<Path
i+1
RegistryPath=RegistryPathlist(i)
GetKey(RegistryPath)
Summy=RegistryValue
GetKey(RegistryPath+"\DefaultIcon")
If RegistryValue<>Summy
Icons+1
Icon(Icons)\RegistryPath=RegistryPath
Icon(Icons)\Name=Summy
SplitIconFile(Icons,RegistryValue)
EndIf
Wend
RegCloseKey_(RegistryHandle)
EndIf
ProcedureReturn Icons
EndProcedure
Procedure.l ImportKeys()
Protected z.s
Icons=0
If FileSize(#WorkshopFile)
If ReadFile(0,#WorkshopFile)
While (Eof(0)=0) And (Icons<#MaxIcons)
z=ReadString(0,#PB_Unicode)
If Left(z,19)="[HKEY_CLASSES_ROOT\" And Right(z,13)="\DefaultIcon]"
z=Mid(z,20,Len(z)-32)
Icons+1
Icon(Icons)\RegistryPath=z
If GetKey(z+"\DefaultIcon")
SplitIconFile(Icons,RegistryValue)
Else
Icon(Icons)\IconFile=""
Icon(Icons)\Index=0
EndIf
If GetKey(z)
Icon(Icons)\Name=RegistryValue
Else
Icon(Icons)\Name="?"
EndIf
EndIf
Wend
EndIf
EndIf
ProcedureReturn Icons
EndProcedure
Procedure SetHeaderImage(GadgetID,ImageIndex.l,Column.l,Align.l)
#HDI_TEXT=2
#HDI_IMAGE=32
#HDI_FORMAT=4
#HDF_BITMAP_ON_RIGHT=4096
#HDF_IMAGE=2048
#HDF_STRING=16384
Structure LVCOLUMN
Mask.l
fmt.l
cx.l
pszText.l
cchTextMax.l
iSubItem.l
iImage.l
iOrder.l
EndStructure
Structure HDITEM
Mask.l
cxy.l
pszText.l
hbm.l
cchTextMax.l
fmt.l
lParam.l
iImage.l
iOrder.l
type.l
pvFilter.l
EndStructure
Protected TextColumn.s=Space(255)
Protected Var.LVCOLUMN\Mask=#LVCF_TEXT
Var\pszText=@TextColumn
Var\cchTextMax=255
SendMessage_(GadgetID,#LVM_GETCOLUMN,Column,@Var)
; variable on HDITEM
Protected VarHeader.HDITEM\Mask=#HDI_IMAGE|#HDI_FORMAT|#HDI_TEXT
VarHeader\fmt=#HDF_IMAGE|Align|#HDF_STRING
VarHeader\iImage=ImageIndex
VarHeader\pszText=@TextColumn
VarHeader\cchTextMax=Len(TextColumn)
SendMessage_(SendMessage_(GadgetID,#LVM_GETHEADER,0,0),#HDM_SETITEM,Column,@VarHeader)
EndProcedure
Procedure SetInformation(line)
Protected nr=Zeiger(line)
Debug "Nr.:"+Str(nr)
;Debug "Show:"+GetGadgetItemText(#Liste,line,#FileColumn)+","+GetGadgetItemText(#Liste,line,#indexColumn)
SetGadgetState(#Icon,LargeIcon(nr))
SetGadgetText(#File,GetGadgetItemText(#Liste,line,#FileColumn)+","+GetGadgetItemText(#Liste,line,#IndexColumn))
EndProcedure
Procedure SetTable(line,Filter)
Protected nr=Zeiger(line)
If Filter&#IconBit
SetGadgetItemText(#Liste,line,Mid(" ×",Icon(nr)\Changed+1,1),#IconColumn)
; Aktualisierung des kleinen Icons --- Schaff ich nicht
EndIf
If Filter&#PathBit
SetGadgetItemText(#Liste,line,Icon(nr)\RegistryPath,#PathColumn)
EndIf
If Filter&#NameBit
SetGadgetItemText(#Liste,line,Icon(nr)\Name,#NameColumn)
EndIf
If Filter&#FileBit
SetGadgetItemText(#Liste,line,Icon(nr)\IconFile,#FileColumn)
EndIf
If Filter&#IndexBit
SetGadgetItemText(#Liste,line,Str(Icon(nr)\Index),#IndexColumn)
EndIf
If Filter&#LineBit
SetGadgetItemText(#Liste,line,Str(line),#LineColumn)
EndIf
If Filter&#NrBit
SetGadgetItemText(#Liste,line,Str(nr),#NrColumn)
EndIf
EndProcedure
Procedure SetVariables(line,Filter)
Protected nr=Zeiger(line)
If Filter&#IndexBit
Icon(nr)\Index=Val(GetGadgetItemText(#Liste,line,#IndexColumn))
EndIf
If Filter&#IconsBit
If Len(Icon(nr)\IconFile)
If FileSize(Icon(nr)\IconFile)>0
Debug "New Icon:"+Str(nr)+" - "+Icon(nr)\IconFile+","+Str(Icon(nr)\Index)
ExtractIconEx_(Icon(nr)\IconFile,Icon(nr)\Index,@LargeIcon(nr),@SmallIcon(nr),1)
EndIf
EndIf
EndIf
EndProcedure
Procedure.s StrapHeader(s.s)
Protected i
i=FindString(s,"\",1)
ProcedureReturn PeekS(@s+i,Len(s)-i-1)
EndProcedure
Procedure.s DoubleBackslash(s.s)
ProcedureReturn ReplaceString(s,"\","\\")
EndProcedure
Procedure.s SingleBackslash(s.s)
ProcedureReturn ReplaceString(s,"\\","\")
EndProcedure
Procedure ReadRegistryFile()
Protected z
; Datei einlesen...
If ReadFile(0,#RegistryFile)
While (Eof(0)=0) ;And (z<15)
z+1
Zeile=ReadString(0,#PB_Unicode)
If PeekB(@Zeile)='['
If GetKey(StrapHeader(Zeile))
;Debug Zeile
;Debug "="+RegistryValue
EndIf
EndIf
Wend
CloseFile(0)
EndIf
EndProcedure
Procedure Main()
Protected i,k,n
Protected Eintrag,quit
SearchKeys("")
;ImportKeys()
If OpenWindow(#Win,0,0,760,420,"Icons",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(#Win))
ImageGadget(#Icon,10,#ListHeight+20,32,32,0)
StringGadget(#File,50,#ListHeight+27,320,23,"")
ButtonGadget(#ButtOk,374,#ListHeight+24,30,28,"Ok")
ButtonGadget(#ButtPrev,408,#ListHeight+24,22,14,"<")
ButtonGadget(#ButtNext,408,#ListHeight+38,22,14,">")
ButtonGadget(#ButtCool,434,#ListHeight+24,30,28,"Cool")
ButtonGadget(#ButtGoReg,490,#ListHeight+26,80,24,"Registry")
ButtonGadget(#ButtExport,580,#ListHeight+26,80,24,"Export")
ButtonGadget(#ButtQuit,670,#ListHeight+26,80,24,"Quit")
ListeID=ListIconGadget(#Liste,10,10,740,#ListHeight,"Icon",30,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(#Liste,1,"Path",180)
AddGadgetColumn(#Liste,2,"Name",150);200
AddGadgetColumn(#Liste,3,"File",250)
AddGadgetColumn(#Liste,4,"Idx",40)
AddGadgetColumn(#Liste,4,"Line",40)
AddGadgetColumn(#Liste,4,"Nr",40)
ChangeListIconGadgetDisplay(#Liste,#PB_ListIcon_Report)
HideGadget(#Liste,1)
; Kopfzeilenhöhe merken...
GetWindowRect_(SendMessage_(ListeID,#LVM_GETHEADER,0,0),Rechteck)
ListeKopfhoehe=Rechteck\bottom-Rechteck\top
;Kopfsymbole=SendMessage_(ListeID,#LVM_GETIMAGELIST,#LVSIL_SMALL,0)
;If Kopfsymbole=0
Kopfsymbole=ImageList_Create_(16,16,#ILC_MASK|#ILC_COLOR32,0,30)
If Kopfsymbole
SendMessage_(ListeID,#LVM_SETIMAGELIST,#LVSIL_SMALL,Kopfsymbole)
Dummy=CatchImage(#Image,?ClearIcon)
ClearIcon=ImageList_AddIcon_(Kopfsymbole,Dummy)
FreeImage(#Image)
Dummy=CatchImage(#Image,?SortIcon)
SortIcon=ImageList_AddIcon_(Kopfsymbole,Dummy)
FreeImage(#Image)
EndIf
SetHeaderImage(ListeID,SortIcon,1,#HDF_BITMAP_ON_RIGHT)
;EndIf
i=0
Entries=0
While i<Icons
i+1
If Len(Icon(i)\IconFile)
If FileSize(Icon(i)\IconFile)>0
;Debug Str(i)+": "+Icon(i)\IconFile+", "+Str(Icon(i)\Index)
ExtractIconEx_(Icon(i)\IconFile,Icon(i)\Index,@LargeIcon(i),@SmallIcon(i),1)
EndIf
EndIf
AddGadgetItem(#Liste,Entries,"",SmallIcon(i))
Zeiger(Entries)=i
SetTable(Entries,#PathBit|#NameBit|#FileBit|#IndexBit|#LineBit|#NrBit)
Entries+1
Wend
HideGadget(#Liste,0)
Eintrag=-1
Repeat
i=WaitWindowEvent(50)
Select i
Case #PB_Event_Menu
Select EventMenu()
Case #Liste
Debug "JA"
Default
Debug "NEIN"
EndSelect
Case #WM_LBUTTONUP
GetWindowRect_(ListeID,Rechteck)
GetCursorPos_(MouseXY)
If (MouseXY\x>Rechteck\left) And (MouseXY\x<Rechteck\right) And (MouseXY\y>Rechteck\top) And (MouseXY\y<Rechteck\top+ListeKopfhoehe)
n=0
i=MouseXY\x-Rechteck\Left
While i>=0
i-SendMessage_(ListeID,#LVM_GETCOLUMNWIDTH,n,0)
n+1
Wend
For i=1 To #NrColumn
SetHeaderImage(ListeID,ClearIcon,i-1,#HDF_BITMAP)
Next i
SetHeaderImage(ListeID,SortIcon,n-1,#HDF_BITMAP)
;Debug n
EndIf
Case #PB_Event_Gadget
Select EventMenu()
Case #Liste
i=GetGadgetState(#Liste)
If (i>=0) And (i<>Eintrag)
Eintrag=i
SetInformation(Eintrag)
EndIf
Case #ButtQuit
quit=1
Case #ButtPrev
i=GetGadgetState(#Liste)
If (i>=0)
k=Val(GetGadgetItemText(#Liste,i,#IndexColumn))
If k>0
SetGadgetItemText(#Liste,i,Str(k-1),#IndexColumn)
SetVariables(i,#IndexBit|#IconsBit)
Icon(Zeiger(i))\Changed=#True
SetTable(i,#IconBit)
SetInformation(i)
SetActiveGadget(#Liste)
EndIf
EndIf
Case #ButtNext
i=GetGadgetState(#Liste)
If (i>=0)
SetGadgetItemText(#Liste,i,Str(Val(GetGadgetItemText(#Liste,i,#IndexColumn))+1),#IndexColumn)
SetVariables(i,#IndexBit|#IconsBit)
Icon(Zeiger(i))\Changed=#True
SetTable(i,#IconBit)
SetInformation(i)
SetActiveGadget(#Liste)
EndIf
Case #ButtOk
i=GetGadgetState(#Liste)
If (i>=0)
n=Zeiger(i)
Icon(n)\Changed=#True
SplitIconFile(n,GetGadgetText(#File))
SetTable(i,#IconBit|#FileBit|#IndexBit)
SetVariables(i,#IconsBit)
SetInformation(i)
SetActiveGadget(#Liste)
EndIf
Case #ButtCool
i=GetGadgetState(#Liste)
If (i>=0)
SetGadgetItemText(#Liste,i,"C:\Win\System\Cool.dll",#FileColumn)
SetGadgetItemText(#Liste,i,"0",#IndexColumn)
SetActiveGadget(#Liste)
SetVariables(i,#IndexBit|#IconsBit)
SetTable(i,#IconBit)
SetInformation(i)
EndIf
Case #ButtExport
If CreateFile(0,#RegistryFile)
WriteStringN(0,"Windows Registry Editor Version 5.00"+#CRLF$)
i=0
While i<Entries
k=Zeiger(i)
WriteStringN(0,"[HKEY_CLASSES_ROOT"+SingleBackslash("\"+Icon(k)\RegistryPath+"\")+"DefaultIcon]")
WriteStringN(0,"@="+#DQUOTE$+DoubleBackslash(Icon(k)\IconFile)+","+Str(Icon(k)\Index)+#DQUOTE$+#CRLF$)
i+1
Wend
CloseFile(0)
EndIf
EndSelect
Case #PB_Event_CloseWindow
quit=1
EndSelect
Until quit
EndIf
ImageList_Destroy_(Kopfsymbole)
EndProcedure
Main()