Code: Select all
DllPackIcons( Folder, DLL, nICON:=1, nGROUPICON:=1 ) { ; By SKAN | 21-Sep-2017 | goo.gl/DjDxzW
Local RT_ICON := 3, RT_GROUPICON := 14, hUPD := 0
Local ICONDATA, nBytes, nOffset, ICONDIR, ICONDIRENTRY, nImages, pICONDIRENTRY
Local File, fICONDIRENTRY, fList := "", IsFolder := 0
nICON := ( nICON<1 ? 1 : nICON ), nGROUPICON := ( nGROUPICON<1 ? 1 : nGROUPICON )
If ( IsFolder := DllCall( "shlwapi\PathIsDirectory", "Str",Folder ) )
Loop, Files, %Folder%\*.*
fList .= A_LoopFileLongPath "`n"
fList := Trim( IsFolder ? fList : Folder, "`n`r" )
Loop, Parse, fList, `n, `r
{
If ( DllCall( "Shell32\ExtractIcon", "Ptr",0, "Str",A_LoopField, "Int",-1 ) <> 1 )
Continue
File := FileOpen(A_LoopField,"r-wd")
If ( IsObject(File)=0 Or File.ReadUINT()<>0x00010000 )
{
File.Close()
Continue
}
hUPD := ( hUPD ? hUPD : DllCall( "BeginUpdateResource", "Str",DLL, "Int",0, "Ptr" ) )
nImages := File.ReadUSHORT()
VarSetCapacity(ICONDIRENTRY,14*nImages+6,0)
File.Seek(0,0)
File.RawRead(ICONDIRENTRY,6)
pICONDIRENTRY := &ICONDIRENTRY+6
fICONDIRENTRY := 6
Loop % nImages
{
File.Seek(fICONDIRENTRY,0)
File.RawRead(pICONDIRENTRY+0,16)
nBytes := NumGet(pICONDIRENTRY+ 8,"UInt")
nOffset := NumGet(pICONDIRENTRY+12,"UInt")
NumPut( nICON,pICONDIRENTRY+12,"UShort")
File.Seek(nOffset,0)
File.RawRead( ICONDATA, nBytes )
DllCall( "UpdateResource", "Ptr",hUPD, "Ptr",RT_ICON, "Ptr",nICON
, "Int",0, "Ptr",&ICONDATA, "UInt",nBytes )
nICON += 1
pICONDIRENTRY += 14
fICONDIRENTRY += 16
}
DllCall( "UpdateResource", "Ptr",hUPD, "Ptr",RT_GROUPICON, "Ptr",nGROUPICON
, "Int",0, "Ptr",&ICONDIRENTRY, "UInt",14*nImages+6 )
nGROUPICON += 1
File.Close()
}
hUPD := ( hUPD ? DllCall( "EndUpdateResource", "Ptr",hUPD, "Int",0 ) >> 64 : 0 )
Return 1
}
Example 1:
Icons will be added in the order populated by File system.
It NTFS, The .ICO files will be in alphabetical order and in FAT32 the list will be in no particular order.
Code: Select all
DLL := DllCreateEmpty( A_ScriptDir "\Icons.dll" )
DllPackIcons( "D:\MyIcons\", DLL )
Icons will be added exactly as it appears in the "files" list.
Code: Select all
DLL := DllCreateEmpty( A_ScriptDir "\Icons.dll" )
Files := "
(
D:\MyIcons\Icon3.ico
D:\MyIcons\Icon1.ico
D:\MyIcons\Icon2.ico
)"
DllPackIcons( Files, DLL )