Results 1 to 2 of 2

Thread: File Icon (from Explorer)

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Posts
    46

    Post

    I have software that show a list of files and i like to know how can i put the icon of each file next to him, like in the windows explorer.

    e.g
    ---

    [icon] app.exe
    [icon] readme.txt


    :eek

    : - )

    Thank you,
    Kiron

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Use the ExtractAssociatedIcon() API to get the Icon associated with the specified type of file, ie.
    Code:
    'Add a Command Button, Picturebox and CommonDialogbox to a Form..
    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 Command1_Click()
        Dim lIcon As Long
        On Error GoTo LoadError
        With CommonDialog1
            .Filter = "All Files|*.*"
            .CancelError = True
            .ShowOpen
            lIcon = ExtractAssociatedIcon(App.hInstance, .FileName, -1)
            Caption = lIcon
            Picture1.AutoRedraw = True
            Call DrawIcon(Picture1.hdc, 0, 0, lIcon)
            Picture1 = Picture1.Image
            SavePicture Picture1, "C:\Image.bmp"
        End With
    LoadError:
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


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