Solved

Getting ICON information

Posted on 2001-08-31
2
171 Views
Last Modified: 2006-11-17
Hai,

Did anybody please tell me, how to get and use the associated icon with a specific extension? For example say, if i want to add a icon associated with the .txt files to a grid control, how can I do it. I want to add icons of all the file types named word,corel draw etc..

Please answer me. I am searching the answer for a long time. I will be very much thanfull to you if you reply.

No problem if it involves lot of API calls and other technical information.

Yours,
Sundar.
0
Comment
Question by:sundar_papco
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6445418
Here's an extract of code.. hopefully you can work it out - let me know if you need help.

Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long

Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Integer
Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long


Sub SetIcon(a_file As String, a_Item As ListItem)
  l_hIcon = ExtractAssociatedIcon(App.hInstance, a_file & Chr$(0), 0)
 
  If l_hIcon <> 0 Then
    picIcon(0).Height = 36 * Screen.TwipsPerPixelY
    picIcon(0).Width = 36 * Screen.TwipsPerPixelX
       
    picIcon(0).AutoRedraw = -1  ' Make the picture's hDC point to the persistent bitmap.
    picIcon(1).AutoRedraw = -1  ' Make the picture's hDC point to the persistent bitmap.
   
    picIcon(0).Cls
    iRetval = DrawIconEx(picIcon(0).hdc, 1, 1, l_hIcon, 32, 32, 0, 0, DI_NORMAL)
    picIcon(0).Refresh
    Set newItem = ImageListListView.ListImages.Add(, GetExtension(a_file), picIcon(0).Image)
   
    picIcon(1).Cls
    iRetval = DrawIconEx(picIcon(1).hdc, 1, 1, l_hIcon, 16, 16, 0, 0, DI_NORMAL)
    picIcon(1).Refresh
    Set newItem = ImageListListViewSmall.ListImages.Add(, GetExtension(a_file), picIcon(1).Image)
   
    iRetval = DestroyIcon(l_hIcon)
  Else
    Set newItem = ImageListListView.ListImages.Add(, GetExtension(a_file), picDefault.Image)
    Set newItem = ImageListListViewSmall.ListImages.Add(, GetExtension(a_file), picDefault.Image)
  End If
  a_Item.SmallIcon = ImageListListViewSmall.ListImages.Item(GetExtension(a_file)).Index
  a_Item.Icon = ImageListListView.ListImages.Item(GetExtension(a_file)).Index

End Sub

There's a bit more to it then this - this is just a quick copy/paste, but hopefully you can work it out from this code..
0
 
LVL 6

Accepted Solution

by:
anthony_glenwright earned 100 total points
ID: 6445425
PS:  The picIcon(0) is a 32 x 32 icon, and the picIcon(1) is a 16 x 16 icon - so you get both sizes...

and I accidentally missed a bit of code:

    picIcon(1).Height = 20 * Screen.TwipsPerPixelY
    picIcon(1).Width = 20 * Screen.TwipsPerPixelX

Which should be just after the line(s) that sets the same properties for picIcon(0).
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month6 days, 2 hours left to enroll

627 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