Solved

Getting associated Icons of Files

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

790 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