Stiletto
Apr 27th, 2001, 11:44 AM
Sups all
i've put an icon of an exe in a picturebox
now i need to know how can i save it and load it back...
can some1 please tell me how to save & load an exe's icon with the ExtractAssociatedIcon Win32 API function?
tnx
Megatron
Apr 27th, 2001, 02:23 PM
You can't use ExtractAssociatedIcon to replace the Application's current icon. It can only be used to retreieve it.
Megatron
Apr 27th, 2001, 02:28 PM
Okay, here's an example of how to save an Icon. First we use ExtractAssociatedIcon to extract the icon, then we use DrawIcon to draw the icon, finally, we use VB's SavePicture() function to save the icon.
Add to a Form with a CommandButton and a PictureBox.
Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon 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
Picture1.AutoRedraw = True
hIcon = ExtractAssociatedIcon(App.hInstance, "C:\WINDOWS\CALC.EXE", 0)
DrawIcon Picture1.hdc, 0, 0, hIcon
Picture1.Refresh
SavePicture Picture1.Picture, "C:\MYICON.ICO"
End Sub