PDA

Click to See Complete Forum and Search --> : Icons: Extracting them, saving them, replacing them


Arzy
Sep 7th, 2000, 10:26 PM
Hi all!

I really looked now over 2 Weeks in the web, and I wandered around in IRC Channels and board, but I didn't find ANY information, how to Save an extracted Icon to a file
or how to replace an Icon of an exefile with another icon (well I believe if I can at least save the icon to a file, the second problem will be solved aswell).
I tried to experiment with the call ExtractIconExA and DrawIcon to a PictureBox, BUT my problem is, that the SavePicture command only saves the icons in bitmap format, and I want them in ICO format.
I don't need any alround functions, a short and fast way to extract and save small icons (those 766 byte large files I think) would do it completely.

Thanks in advance for your help,

Arzy

Sep 8th, 2000, 02:22 PM
You can do this but it will be really hard. The icon is stored in the EXE itself hence you would have to binary edit it in order to change the icon.

Arzy
Sep 8th, 2000, 04:03 PM
Originally posted by Megatron
You can do this but it will be really hard. The icon is stored in the EXE itself hence you would have to binary edit it in order to change the icon.

I'd be really glad if you can tell me at least HOW I extract icons and save them as Icons. The replacement of the EXE Icon is no difficulty then. If you want to know more about the project or you want to help me with the code anyways, I'd say we start an e-mail contact

Sep 8th, 2000, 05:09 PM
Sure. Just use the ExtractIcon API to extract the Icon and use DrawIcon to draw the icon. This will give you a bitmap (of the Icon) and you can simply convert it to an Icon using an ImageList control.

Add the following to a Form with a PictureBox, CommandButton and ImageList.

Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long

Private Sub Command1_Click()
Dim hIcon As Long
'Extract the icon from Calculator
hIcon = ExtractIcon(App.hInstance, "C:\Windows\Calc.exe", 0)
'Draw the Icon on to Picture1
DrawIcon Picture1.hdc, 0, 0, hIcon
Picture1.Picture = Picture1.Image
'Convert the Bitmap to an Icon
ImageList1.ListImages.Add , , Picture1.Picture
Set Picture1.Picture = Nothing
Set Picture1.Picture = ImageList1.ListImages(1).ExtractIcon
'Save the Icon
SavePicture Picture1.Picture, "C:\Windows\Desktop\MyIco.ico"
End Sub

Private Sub Form_Load()
'Set initial settings
Picture1.AutoRedraw = True
Me.ScaleMode = vbPixels
End Sub

Sep 9th, 2000, 08:12 AM
The ImageList control looks like 3 rectangles stacked on top of each other. It's should be underneath the ProgressBar.

The library it's located in is called Windows Common Controls.