IMO, the functions provide a useful additional option to share own icons or images by only one file. That's why I decided to post revised versions of SKAN's functions in the new forum.
Code: Select all
#NoEnv
SetBatchLines, -1
ImlFile := "Test.iml"
; --------------------------------------------------------------------------------------------------------------------------------
HIL1 := IL_Create(10, 0, 1)
Loop, 40
IL_Add(HIL1, "Shell32.dll", A_Index)
Gui, Add, Text, xm w480, Loaded from Shell32.dll:
Gui, Add, ListView, xm y+2 w480 h510 Icon, Icon
LV_SetImageList(HIL1, 0)
Loop, 40
LV_Add("Icon" . A_Index )
; --------------------------------------------------------------------------------------------------------------------------------
IL_Save(HIL1, ImlFile)
HIL2 := IL_Load(ImlFile)
Gui, Add, Text, ym w480, Loaded from saved ImageList:
Gui, Add, ListView, xp y+2 w480 h510 Icon, Icon
LV_SetImageList(HIL2, 0)
Loop, 40
LV_Add("Icon" . A_Index )
; --------------------------------------------------------------------------------------------------------------------------------
Gui, Add, Text, xm, Icon 1 from loaded ImageList:
Gui, Add, Pic, xm y+2 Border, % "HICON:" . IL_EX_GetHICON(HIL2, 1)
Gui, Show, , ImageList Test
Return
; ================================================================================================================================
GuiClose:
FileDelete, %ImlFile%
ExitApp
; ================================================================================================================================
IL_Save(HIL, File) {
; Originally released by SKAN -> www.autohotkey.com/forum/viewtopic.php?t=72282
Size := 0
If (FileObj := FileOpen(File, "w")) {
DllCall("Ole32.dll\CreateStreamOnHGlobal", "Ptr", 0, "Int", 1, "PtrP", IStream, "UInt")
DllCall("ImageList_Write", "Ptr", HIL, "Ptr", IStream, "UInt")
DllCall("Ole32.dll\GetHGlobalFromStream", "Ptr", IStream, "PtrP", HGlobal, "UInt")
Data := DllCall("GlobalLock", "Ptr", HGlobal )
Size := DllCall("GlobalSize", "Ptr", HGlobal )
Size := FileObj.RawWrite(Data + 0, Size)
FileObj.Close()
DllCall("GlobalUnlock", "Ptr", Data)
ObjRelease(IStream)
DllCall("GlobalFree", "Ptr", HGlobal)
}
Return Size
}
; ================================================================================================================================
IL_Load(File) {
; Originally released by SKAN -> www.autohotkey.com/forum/viewtopic.php?t=72282
HIL := 0
If (FileObj := FileOpen(File, "r")) {
Size := FileObj.Length
HGlobal := DllCall("GlobalAlloc", "UInt", 2, "UInt", Size, "UPtr")
Data := DllCall("GlobalLock", "Ptr", HGlobal, "UPtr")
FileObj.RawRead(Data + 0, Size)
FileObj.Close()
DllCall("GlobalUnlock", "Ptr", Data)
DllCall("Ole32.dll\CreateStreamOnHGlobal", "Ptr", HGlobal, "Int", 1, "PtrP", IStream, "UInt")
HIL := DllCall("ImageList_Read", "Ptr", IStream, "UPtr")
ObjRelease(IStream)
DllCall("GlobalFree", "Ptr", HGlobal)
}
Return HIL
}
; ======================================================================================================================
; Part of the IL_EX library -> autohotkey.com/boards/viewtopic.php?f=6&t=1273
; ======================================================================================================================
; IL_EX_GetHICON(ILID, Index[, Styles := 0x00])
; Function: Creates an icon from an image in an image list.
; Parameters: Styles - A combination of drawing styles (see IL_EX_Draw()).
; Default: 0x20 (ILD_IMAGE)
; Return values: Returns the handle to the icon if successful, or NULL otherwise.
; MSDN: http://msdn.microsoft.com/en-us/library/bb761548(VS.85).aspx
; ======================================================================================================================
IL_EX_GetHICON(ILID, Index, Styles := 0x20) {
Return DllCall("ComCtl32.dll\ImageList_GetIcon", "Ptr", ILID, "Int", Index - 1, "UInt", Styles, "UPtr")
}
- Changed IL_Load() to work on Win XP.
The previously used SHCreateMemStream() function is not exported by name on XP, thanks Drugwash.
IL_Load_VBMP() (requested by Drugwash)
This function can be used to load 'vertically-stacked' bitmaps as used by some Windows themes from BMP files on Win XP+. It has been tested with some few files only, so it might not work properly in every case.