madRes - saving .ico file

delphi package - madRes, madTools, madStrings, ...

madRes - saving .ico file

Postby Nikse » Sat Nov 13, 2004 9:05 pm

Hi !

madRes looks very nice indeed.

I've written a small icon grabber using ExtractIcon(Ex) to list all icons in
an .exe file... but delphi's built in TIcon cannot save icons in WinXP
alphablended format (or even in 256 colors).
Is this (listing all icons + saving) possible using madRes... and how (sample code)?

TIA
Nikse
Nikse
 
Posts: 3
Joined: Sat Nov 13, 2004 9:03 pm
Location: Denmark

Postby madshi » Mon Nov 15, 2004 7:49 am

Enumerating resources currently isn't exported by madRes. It would be possible to do that, but would need some work.

You can use this approach, though:

(1) Use LoadLibraryEx(LOAD_LIBRARY_AS_DATAFILE) to load the target exe/dll into memory.
(2) Use EnumResourceNames(dllHandle, RT_GROUP_ICON) to enumerate all icon groups.
(3) Use FreeLibrary to unload the target exe/dll again.
(4) Use madRes.BeginUpdateResourceW to open the exe/dll for madRes.
(5) Use madRes.SaveIconGroupResourceW to save all icon groups (which you enumerated in step (2)) to a file.
(6) Call madRes.EndUpdateResourceW and discard any changes.

Sorry, no time to write sources for you.
madshi
Site Admin
 
Posts: 10066
Joined: Sun Mar 21, 2004 5:25 pm

Postby Nikse » Mon Nov 15, 2004 11:15 pm

Thx, great!

Almost there... I think. Enumeration is working (according to ResHacker).

I can save the main icon like this:
result := SaveIconGroupResourceW(resUpdateHandle, 'MAINICON', 0, 'c:\test.ico');

But how do I save an icon called "74" from RT_ICONS?
result := SaveIconGroupResourceW(resUpdateHandle, 'RT_ICON_74', 0, 'c:\test2.ico'); // does not work
Nikse
 
Posts: 3
Joined: Sat Nov 13, 2004 9:03 pm
Location: Denmark

Postby madshi » Tue Nov 16, 2004 7:27 am

SaveIconGroupResourceW is only meant for icon groups, not for single icons. If you need to extract single icons, you probably need to look at how madRes does it for icon groups and then modify/extend the functionality for single icons. But why do you need that? Usually all single icons are part of at least one icon group.
madshi
Site Admin
 
Posts: 10066
Joined: Sun Mar 21, 2004 5:25 pm


Return to madBasic

Who is online

Users browsing this forum: No registered users and 0 guests