v1:
Code: Select all
IndexOfIconResource_EnumIconResources(hModule, lpszType, lpszName, lParam)
{
NumPut(NumGet(lParam+4)+1, lParam+4)
if (lpszName = NumGet(lParam+0))
{
NumPut(1, lParam+8)
return false ; break
}
return true
}
Code: Select all
IndexOfIconResource_EnumIconResources(hModule, lpszType, lpszName, lParam){
NumPut("UPtr", NumGet(lParam + 4, "UPtr") + 1, lParam + 4)
if (lpszName = NumGet(lParam + 0, "UPtr")){
NumPut("UPtr", 1, lParam + 8)
return false ; break
}
return true
}
;V2 full script
Code: Select all
#Requires AutoHotKey v2.0-beta.1
MsgBox(getExtIcon("ahk"))
getExtIcon(Ext){
from := RegRead("HKEY_CLASSES_ROOT\." Ext)
DefaultIcon := RegRead("HKEY_CLASSES_ROOT\" from "\DefaultIcon")
DefaultIcon := StrReplace(DefaultIcon, '"')
DefaultIcon := StrReplace(DefaultIcon, "%SystemRoot%", A_WinDir)
DefaultIcon := StrReplace(DefaultIcon, "%ProgramFiles%", A_ProgramFiles)
DefaultIcon := StrReplace(DefaultIcon, "%windir%", A_WinDir)
I := StrSplit(DefaultIcon,",")
Return I[1] " - " IndexOfIconResource( I[1], RegExReplace(I[2], "[^\d]+") )
}
IndexOfIconResource(Filename, ID){
hmod := DllCall("GetModuleHandle", "str", Filename)
; If the DLL isn't already loaded, load it as a data file.
loaded := !hmod
&& hmod := DllCall("LoadLibraryEx", "str", Filename, "uint", 0, "uint", 0x2)
enumproc := CallbackCreate(IndexOfIconResource_EnumIconResources, "F")
param := Buffer(12, 0), NumPut("UPtr", ID, param, 0)
; Enumerate the icon group resources. (RT_GROUP_ICON=14)
DllCall("EnumResourceNames", "uint", hmod, "uint", 14, "uint", enumproc, "uint", ¶m:=0)
DllCall("GlobalFree", "uint", enumproc)
; If we loaded the DLL, free it now.
if loaded
DllCall("FreeLibrary", "uint", hmod)
return NumGet(param, 8) ? NumGet(param, 4) : 0
}
IndexOfIconResource_EnumIconResources(hModule, lpszType, lpszName, lParam){
NumPut("UPtr", NumGet(lParam + 4, "UPtr") + 1, lParam + 4)
if (lpszName = NumGet(lParam + 0, "UPtr")){
NumPut("UPtr", 1, lParam + 8)
return false ; break
}
return true
}
;V1 full script
Code: Select all
#Requires AutoHotkey v1.1.33+
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
MsgBox, % getExtIcon("ahk")
getExtIcon(Ext) {
I1 := I2:= ""
RegRead, from, HKEY_CLASSES_ROOT, .%Ext%
MsgBox % from
RegRead, DefaultIcon, HKEY_CLASSES_ROOT, %from%\DefaultIcon
StringReplace, DefaultIcon, DefaultIcon, `",,all
StringReplace, DefaultIcon, DefaultIcon, `%SystemRoot`%, %A_WinDir%,all
StringReplace, DefaultIcon, DefaultIcon, `%ProgramFiles`%, %A_ProgramFiles%,all
StringReplace, DefaultIcon, DefaultIcon, `%windir`%, %A_WinDir%,all
StringSplit, I, DefaultIcon, `,
Return I1 " - " IndexOfIconResource( I1, RegExReplace(I2, "[^\d]+") )
}
IndexOfIconResource(Filename, ID)
{
hmod := DllCall("GetModuleHandle", "str", Filename)
; If the DLL isn't already loaded, load it as a data file.
loaded := !hmod
&& hmod := DllCall("LoadLibraryEx", "str", Filename, "uint", 0, "uint", 0x2)
enumproc := RegisterCallback("IndexOfIconResource_EnumIconResources","F")
VarSetCapacity(param,12,0), NumPut(ID,param,0)
; Enumerate the icon group resources. (RT_GROUP_ICON=14)
DllCall("EnumResourceNames", "uint", hmod, "uint", 14, "uint", enumproc, "uint", ¶m)
DllCall("GlobalFree", "uint", enumproc)
; If we loaded the DLL, free it now.
if loaded
DllCall("FreeLibrary", "uint", hmod)
return NumGet(param,8) ? NumGet(param,4) : 0
}
IndexOfIconResource_EnumIconResources(hModule, lpszType, lpszName, lParam)
{
NumPut(NumGet(lParam+4)+1, lParam+4)
if (lpszName = NumGet(lParam+0))
{
NumPut(1, lParam+8)
return false ; break
}
return true
}