Solved

Getting associated Icons of Files

Posted on 2000-05-09
5
197 Views
Last Modified: 2010-05-02
I want to store the associated Icons of Files in an VB ImageList.

I'm using the DLL-Function ExtractAssociatedIcon and get a hadle to the icon.

But I don't know how to continue to store these icons in an ImageList.
Must I use another DLL-Function to do this or is there a VB-Function I can use?
0
Comment
Question by:rainerHOLZ
  • 4
5 Comments
 
LVL 3

Accepted Solution

by:
paulstamp earned 100 total points
ID: 2795731
This is code I wrote, after raising a similar question here on EE

Public Sub ExtractIconToImageList(ByVal sFileName As String, ByRef imlTarget As ImageList, ByRef picTarget As PictureBox, nImageIndex As Integer, Optional nIconIndex As Integer = 0)
    '~^--------------------------------------------------------------------------------
    '~ Extracts an icon from the passed in file and adds to the specified imagelist. The
    '~ index specifies which icon to retrieve if there is more than one. PicTarget is
    '~ used to store the image prior to storing in the listview, nImageIndex is the index
    '~ to use in the imagelist.
    '~^
    '~^  #     DATE      USER     CHANGE
    '~^ -------------------------------------------------------------------------------
    '~%  1  16-Feb-2000 pauls     Created
    '~^
    '~^--------------------------------------------------------------------------------

    Dim lIcon As Long
   
    lIcon = ExtractIcon(App.hInstance, sFileName, nIconIndex)
    Set picTarget.Picture = LoadPicture("")
    picTarget.AutoRedraw = True
    Call DrawIcon(picTarget.hdc, 0, 0, lIcon)
    picTarget.Refresh
    picTarget.AutoRedraw = False
    Set picTarget.Picture = picTarget.Image
    Call imlTarget.ListImages.Add(, "i" & nImageIndex, picTarget.Picture)
       
   
End Sub
0
 
LVL 3

Expert Comment

by:paulstamp
ID: 2795734
Just one note of explanation... you need a temporary picture box as an intermediate stage - I have an invisible picture box on a form and use that.
0
 
LVL 3

Expert Comment

by:paulstamp
ID: 2795735
Another comment - to extract associated icon you'll need to change the first line of the procedure - my code gets the icon from the file itself.
0
 

Author Comment

by:rainerHOLZ
ID: 2796162
Thanks, you helped me a lot.
0
 
LVL 3

Expert Comment

by:paulstamp
ID: 2796260
No problem.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now