/* LoadIconfromICO() : Loads and returns handle of an Icon from .ICO file Screenshot: http://arian.suresh.googlepages.com/loadicon.png LoadIconFromICO() DEMO by SKAN ||| Created: 11-05-2008 ||| Last Modified: 11-05-2008 */ #SingleInstance, Force SetWorkingDir %A_ScriptDir% IfNotExist, 0131-00239.ico UrlDownloadToFile, http://arian.suresh.googlepages.com/0131-00239.ico, 0131-00239.ico Icons := "48x48-4|32x32-4|16x16-4|48x48-8|32x32-8|16x16-8|48x48-32|32x32-32|16x16-32" Gui, Add, DDL, w130 Choose1 R5 Sort -Theme vSel gSelect, %Icons% Gui, Add, Picture, w130 h130 Border 0x203 hwndIcon1 Gui, Show, w150, Icon Select: GuiControlGet, Sel StringSplit, P, Sel,- hIcon := LoadIconFromICO( "0131-00239.ico", P1, P2 ) SendMessage, ( STM_SETIMAGE:=0x172 ), ( IMAGE_ICON:=0x1 ), hIcon,, ahk_id %Icon1% Return LoadIconFromICO( Ico, WxH, BPP ) { hFile := DllCall( "_lopen", Str,Ico, UInt,0 ) VarSetCapacity( Hdr, 6, 0 ) DllCall( "_lread", UInt,hFile, Str,Hdr, UInt,6 ) Icons := NumGet( Hdr, 4, "UShort" ) If ( NumGet( Hdr ) <> 65536 || Icons > 256 ) { DllCall( "_lclose", UInt,hFile ) Return -1 } StringSplit, D, WxH, x Loop %Icons% { VarSetCapacity( DIRE, 16,0 ) DllCall( "_lread", UInt,hFile, Str,DIRE, UInt,16 ) If ( NumGet( DIRE,0,"UChar" ) = D1 && NumGet( DIRE,1,"UChar" ) = D2 && NumGet( DIRE,6,"UChar" ) = BPP ) { VarSetCapacity( ICOD, ( DataLen := NumGet( DIRE,8 )), 0 ) DllCall( "_llseek", UInt,hFile, UInt,NumGet( DIRE,12), UInt,0 ) DllCall( "_lread", UInt,hFile, Str,ICOD, UInt,DataLen ) Break } } If ( ! DataLen ) { DllCall( "_lclose", UInt,hFile ) Return -2 } DllCall( "_lclose", UInt,hFile ) Return DllCall( "CreateIconFromResourceEx", UInt,&ICOD, UInt,BPP, Int,1 , UInt, 0x00030000, Int,W, Int,H, UInt,(LR_SHARED := 0x8000) ) }