Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pull an Icon from an exe and put it in a picture box

Status
Not open for further replies.

eblattner

Programmer
Aug 10, 2000
33
I am creating a simple shell program. When the user minimizes a window, they can't get it back (no task bar), all they have is the shell. I created a picture box and placed 12 images in it, one fof each button on the shell. What i need to do is pull the icon out of the exe the user runs, and pot it in the cooresponding image so they can click the image and restore the program window. All this needs to be done in code since the 12 buttons are customizable. Placing an icon in the image control is not a proble, but I can't fighre out how to get it from the exe.

if the user chooses to run Word, for instance, how can I get the word icon from the exe?
 
Look at the ExtractIcon api call. It returns a handle to the icon. Be sure to call CloseHandle on it (if not NULL).
[tt]
Public Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long

Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Long) As Long
[/tt]

Chip H.
 
Extract Icon From File

'This example will show you how to extract icon from Any file.
'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Add 1 Picture Box (named Picture1) to your form. Set The Picture Box AutoRedraw
'property to True.
'Insert this code to the module :

Public Const DI_MASK = &H1
Public Const DI_IMAGE = &H2
Public Const DI_NORMAL = DI_MASK Or DI_IMAGE
Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" _
(ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long
Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, _
ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth _
As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal _
diFlags As Long) As Long
Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long

'Insert the following code to your form:

Private Sub Form_Load()
'Replace 'C:\Autoexec.bat' with the file you want to get its icon.
mIcon = ExtractAssociatedIcon(App.hInstance, "C:\Autoexec.bat", 2)
'Draw the icon on the Picture Box. To draw the icon on a Form, Replace the
'Picture1' Below with your form name
DrawIconEx Picture1.hdc, 0, 0, mIcon, 0, 0, 0, 0, DI_NORMAL
'Remove the icon from the memory
DestroyIcon mIcon
End Sub

Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top