Results 1 to 5 of 5

Thread: Picture from exe

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Picture from exe

    How can i put a exe's icon in a picture box??

  2. #2
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    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??
    Don't Rate my posts.

  3. #3
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    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
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  4. #4
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    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

  5. #5
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    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
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

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