Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

load an icon by number from *.dll


  • Please log in to reply
10 replies to this topic
toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Does anyone know how to load an icon by number (if there are more then one icon) from an *.dll file and get the handle back?

This code works for an *.ico file but not for an *.dll file
iconfile = xxx.ico
hicon := DllCall("LoadImage", UInt, NULL, Str, iconfile, UInt, 1, Int, 16, Int, 16, UInt, 0x2010)
I hope there exists a similar approach for *.dll files.

I ask, because it would perfectly extend SB_icon().

I have found a post from Chris, who uses IL_Add() to get icons from an dll and adds them to Tabs with SendMessages. Could this somehow be used to get the handle?

I have had a look at the MSDN doc. on LoadImage. It seams to me that LoadImage could load an image form an dll file. But I do not know how to get it working. I do not know how to get the hex values of the vars. Could someone help me please?
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Try the ExtractIcon function, looks like what you want...

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
I tried
hicon := DllCall("ExtractIcon", UInt, NULL, Str, file, UInt, IconID)
with file being the path an file of the shell32.dll and IconID = 6.
but without success. Any ideas?
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
We have an ErrorLevel of -4:
ExtractIcon is in Shell32.dll
I had to add the A suffix as well, since this is not a "standard" DLL (ie. one automatically referenced by AutoHotkey).
hicon := DllCall("Shell32\ExtractIconA", UInt, NULL, Str, file, UInt, iconID)


toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Thanks a lot, now I get an icon.
Unfortunately the icon is pretty large, too large for the statusbar. Is there a way I could use "Shell32\ExtractIconExA" to get a handle to the small icons? or could this be done with "Shell32\ExtractIconA" as well?
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
From what I see, it looks like you have indeed to use ExtractIconEx. That's a pity because this function is less convenient from the point of view of using it in AHK... (scanning an array of handles)

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
I'm currently taking a look at AHKs source code, since I believe Chris must have written something like this for the IL_Add(). But C++ is like chinese to me. I found the BIF_IL_Add() function in the script2.cpp. He uses a function LoadPicture() which I couldn't find yet.

Edit: Found it in util.cpp. In that function LoadPicture() the code uses ExtractIcon(), which I haven't found yet.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
ExtractIcon is the Windows API function that PhiLho provided a link for, above.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Thanks for the reply. But how does AHK get the small icon form a dll, and not the large one?

E.g. with IL_Create([InitialCount, GrowCount, LargeIcons?]) the icon size is specified and with IL_Add(ImageListID, Filename [, IconNumber, ResizeNonIcon?]) the icons are loaded. I can't get the DllCalls together to do it.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.