Extract Associated Icon From EXE File

'This example will show you how to extract icon from EXE file. The file has to be file that
'his associate files (the files that opens with him) got his icon. For example the file
'winamp.exe that when it's installed in your computer, all the mp3 files will get his icon.
'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Add 1 PictureBox (named Picture1) to your form.
'Insert this code to the module :

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

'Insert this code to your form:

Private Sub Form_Load()
Dim Path As String, strSave As String
Dim returnl As Long, return2 As Long
strSave = String(200, Chr$(0))
Picture1.AutoRedraw = True
'Replace 'c:\windows\regedit.exe' with the name of the file that
'you want to extract his icon.

return1 = ExtractIcon(Me.hWnd, "c:\windows\regedit.exe", 2)
return2 = DrawIcon(Picture1.hdc, 0, 0, return1)
End Sub

Go Back