Click to See Complete Forum and Search --> : display icon associated with program


smchristensen
March 20th, 2001, 10:25 AM
Is there a way to make a treeview control show the icon that is associated with a file without loading all the pictures in a imagelist? Maybe by using explorer?

epelyavski
March 21st, 2001, 11:14 PM
I think you don't have to load all pictures in a imagelist. You can use ListImages.Add method:


...
imgList.ListImages.Add , "File1", picPicture.Picture
lstBrowser.ListItems.Add , , "File Name", "File1"
...




Another question is how to get those icons associated with files. By using the Registry? Any ideas?

Next question!

Cimperiali
March 22nd, 2001, 07:23 AM
I have not tried -and I cannot, by now - but if I 'd to display iconns from file, I would give a look at ExtractIcon inside Vb...

Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.

Clearcode
March 22nd, 2001, 08:18 AM
Like this?


private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (byval hInst as Long, byval lpszExeFileName as string, byval nIconIndex as Long) as Long


'\\ --[IconsFromFilename]-------------------------------------------------------------------
'\\ Returns a collection of ApiIcon objects from the filename given.
'\\ ----------------------------------------------------------------------------------------
'\\ You have a royalty free right to use, reproduce, modify, publish and mess with this code
'\\ I'd like you to visit http://www.merrioncomputing.com for updates, but won't force you
'\\ ----------------------------------------------------------------------------------------
public Function IconsFromExeFilename(byval Filename as string) as Collection

Dim lIndex as Long
Dim lIconCount as Long
Dim lRet as Long

Dim colIcons as Collection
Dim sExeString as string
Dim thisIcon as Long

'\\ Initialise the collection
set colIcons = new Collection

'\\ get the number of items
lIconCount = ExtractIcon(App.hInstance, Filename, -1)
If lIconCount > 0 then
for lIndex = 0 to lIconCount - 1
lRet = ExtractIcon(App.hInstance, Filename, lIndex)
If lRet > 0 then
thisIcon = lRet
colIcons.Add thisIcon
End If
next lIndex
End If

'\\ Return the collection
set IconsFromExeFilename = colIcons

End Function




HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com