Results 1 to 5 of 5

Thread: HELP. How to put an icon of an exe file into image?

  1. #1
    Stiletto
    Guest

    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?

  2. #2
    Stiletto
    Guest
    ne1?

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    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

  4. #4
    Stiletto
    Guest
    ' Draw it in the PictureBox, picIcon
    Call DrawIcon(picIcon.hDC, 0, 0, hIcon)

    can i replace it with
    image.picture = loadpicture(hIcon)
    ?

  5. #5
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    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
  •  



Click Here to Expand Forum to Full Width