|
-
Mar 6th, 2002, 10:37 PM
#1
Picture from exe
How can i put a exe's icon in a picture box??
-
Mar 7th, 2002, 03:11 AM
#2
PowerPoster
Umm, If I want to get a programs Icon, I usually take a good picture of it in Windows Explorer using Print Screen, or you can find out what sort of images are stored in an exe by changing a programs icons, again using the Print Screen button.
Does anyone know a better way??
-
Mar 7th, 2002, 04:08 AM
#3
Frenzied Member
There's an Extracticon API call that can do this thus:
Code:
Option Explicit
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
'\\ --[IconsFromFilename]-------------------------------------------------------------------
'\\ Returns a collection of ApiIcon objects from the filename given.
'\\ ----------------------------------------------------------------------------------------
'\\ (c) 2001 - Merrion Computing. All rights to use, reproduce or publish this code reserved
'\\ Please check http://www.merrioncomputing.com for updates.
'\\ ----------------------------------------------------------------------------------------
Public Property Get IconsFromExeFilename(ByVal Filename As String) As Collection
Dim lIndex As Long
Dim lIconCount As Long
Dim lRet As Long
Dim colIcons As Collection
Dim thisIcon As ApiIcon
'\\ Initialise the collection
Set colIcons = New Collection
'\\ Get the number of items
lIconCount = ExtractIcon(App.hInstance, Filename, -1)
If lIconCount > 0 Then
For lIndex = 0 To lIconCount - 1
lRet = ExtractIcon(App.hInstance, Filename, lIndex)
If lRet > 0 Then
Set thisIcon = New ApiIcon
thisIcon.hIcon = lRet
colIcons.Add thisIcon
End If
Next lIndex
End If
Which you could adapt to your needs....
HTH,
Duncan
-
Mar 7th, 2002, 04:26 AM
#4
Fanatic Member
With the example that you posted how do you use the icons??
Eg I would like
Also it doesnt quite work as the ApiIcon type is not declared.
Leather Face is comin...
MCSD
-
Mar 7th, 2002, 06:01 AM
#5
Frenzied Member
ApiIcon is part of the EventVB.dll - however here is some code you would probably find more useful:
You need a form with a picture box (called Picture1) with AutoRedraw set to true, a filelist called File1 with mask set to *.exe and a drive list box called drive1.
Code:
Option Explicit
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 DrawIconApi Lib "user32" Alias "DrawIcon" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub File1_Click()
Call DrawIconsFromExeFilename(File1.Filename)
End Sub
'\\ --[DrawIconsFromFilename]---------------------------------------------
'\\ (c) 2001 - Merrion Computing. All rights to use, reproduce or publish this code reserved
'\\ Please check http://www.merrioncomputing.com for updates.
'\\ --------------------------------------------------------------------------------
Public Sub DrawIconsFromExeFilename(ByVal Filename As String)
Dim lIndex As Long
Dim lIconCount As Long
Dim lRet As Long
Dim x As Long, y As Long
Picture1.Cls
'\\ Get the number of items
lIconCount = ExtractIcon(App.hInstance, Filename, -1)
If lIconCount > 0 Then
For lIndex = 0 To lIconCount - 1
lRet = ExtractIcon(App.hInstance, Filename, lIndex)
If lRet > 0 Then
Call DrawIconApi(Picture1.hdc, x, y, lRet)
If x > 200 Then
x = 0
y = y + 40
Else
x = x + 40
End If
End If
Next lIndex
End If
End Sub
HTH,
Duncan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|