The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Smith2008 on February 20, 2010, 07:01:11 AM

Title: How to save an ICON to Disk
Post by: Smith2008 on February 20, 2010, 07:01:11 AM
Hi
My question is:
How to save an ICON to Disk using icon handle.

my code is this:

.const
szFileName             DB  "C:\app.exe",0

.data?
hInstance dd ?
hIcon1  dd ?;   // icon handle   
hdc1 dd ?;        // handle of display context
.
.
.
invoke ExtractIcon,hInstance,offset szFileName,0
mov hIcon1,eax
invoke GetDC,hWin
mov hdc1,eax
invoke DrawIcon,hdc1, 10, 20, hIcon1



I have got the HICON and assigned to hdc1 ,but have to save to harddisk? ::)

any help or hint will be appreciated.
Title: Re: How to save an ICON to Disk
Post by: BlackVortex on February 20, 2010, 07:12:36 AM
I think you have to use GetDIBits to get a buffer with the actual bitmap bits. I'm not sure how it should be saved to disk (don't know about the bmp format)

You may need to load the handle with LoadImage. Can you at least show the ico correctly at the moment ? Leave the disk saving for last.
Title: Re: How to save an ICON to Disk
Post by: Smith2008 on February 20, 2010, 07:26:37 AM
invoke DrawIcon,hdc1, 10, 20, hIcon1
with this code the main form which has hWin handle,And yes it draws and shows the icon in the Form.
I have the handle of ICON on app.exe which is in other directory.
Title: Re: How to save an ICON to Disk
Post by: BlackVortex on February 20, 2010, 07:46:51 AM
Ok, then get the bits with that function I mentioned.
Title: Re: How to save an ICON to Disk
Post by: Nordwind64 on February 20, 2010, 12:09:28 PM
Here is an solution with API: http://www.activevb.de/tipps/vb6tipps/tipp0729.html