Click to See Complete Forum and Search --> : Saving a HICON


Lighthill
June 8th, 2003, 01:56 PM
Hi,

Does anyone know how i can save an icon represented by an HICON Handle in a .ico file ?

I checked out this here:
http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_20272806.html

... but it doesn't work :-(

It would be great if anyone could give me a link with existing code or any other help.

Bengi
June 8th, 2003, 03:44 PM
Icons are stored in the resource section of the exe's PE Header..
take a look of resource dumpers =)
u can also dump it from memory if u know its pointer... =)

JamesSchumacher
June 9th, 2003, 02:12 PM
LoadLibraryEx(LPCTSTR strFileName,HANDE hFile,DWORD dwFlags);
FindResource(HMODULE hModule,LPCTSTR strResourceName,LPCTSTR strResourceType);
SizeOfResource(HMODULE hModule,HRSRC hResource);
LoadResource(HMODULE hModule,HRSRC hResInfo);
LockResource(HGLOBAL hResData); // this get's you the actual pointer to the resource data. You can write this to a file using the value gotten from SizeOfResource()


Don't know how to save a HICON handle, but if you want to extract a resource from an *.exe, this would be the route to go.

Lighthill
June 9th, 2003, 05:33 PM
Hi, thanks for your replies. The way to handle an icon resource by the FindResource/LockResource.... functions makes it easy to save a single icon and CreateIconFromResource(Ex) to load it from a file. Saving it through LockResource doesn't include the Icon header and the ICONENTRY structures but that is not the problem :-)