Solved

Getting associated Icons of Files

Posted on 2000-05-09
5
198 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

863 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

20 Experts available now in Live!

Get 1:1 Help Now