|
-
Apr 27th, 2001, 06:32 AM
#1
HELP. How to put an icon of an exe file into image?
Hey
In my app, the user need to choose an icon. He can do it by choosing an ico file (*.ico) or an exe file (*.exe).
I know how to set the pattern to two diffrent extantions, but whent he user clicks OK the icon he choosed need to be in an image, but the image can't load the icon of the exe (in case the user choosed an exe file as in icon)
what can i do so image.picture will get the exe's?
-
Apr 27th, 2001, 06:44 AM
#2
-
Apr 27th, 2001, 06:45 AM
#3
Guru
You should use the ExtractAssociatedIcon Win32 API function:
Code:
Option Explicit
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 cmdSetIcon_Click()
Dim hIcon As Long
' Extract icon from Notepad.exe
hIcon = ExtractAssociatedIcon(0, "Notepad.exe", 0)
If hIcon = 0 Then Exit Sub
' Draw it in the PictureBox, picIcon
Call DrawIcon(picIcon.hDC, 0, 0, hIcon)
End Sub
VBBrowser v2.2.1
By the way, this function is incorrectly declared in the API viewer
-
Apr 27th, 2001, 06:50 AM
#4
' Draw it in the PictureBox, picIcon
Call DrawIcon(picIcon.hDC, 0, 0, hIcon)
can i replace it with
image.picture = loadpicture(hIcon)
?
-
Apr 27th, 2001, 07:11 AM
#5
Guru
Nope, you can't use an Image for this, since it is embedded in the form, and therefore isn't a control and doesn't have its own device-context. 
I suggest you use a PictureBox instead of an Image if you are dynamically changing the picture. An Image is only for decoration.
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
|