|
-
Jan 10th, 2000, 04:03 PM
#1
Thread Starter
Addicted Member
I've seen tons of code on extracting icons from dll's and exe's etc. But what I'd like to be able to do is determine and extract an icon based on it's assosiation with a file extension so that I can ... say load a listView control with a directory of files and have the appropriate icon.
I'm guessing the registry would be where to determine the assosiations .... any ideas?
------------------
Micah Carrick
http://micah.carrick.com
[email protected]
ICQ: 53480225
-
Jan 11th, 2000, 02:28 AM
#2
You can use the ExtractAssociatedIcon API, here's a quick Example:
Add a Picturebox, Command Button and CommonDialogbox to a Form..
Code:
Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long
Private 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
Private Sub Command1_Click()
Dim lIcon As Long
On Error GoTo User_Cancelled
With CommonDialog1
.Flags = cdlOFNNoValidate
.CancelError = True
.DialogTitle = "Select a File.."
.Filter = "All Files (*.*)|*.*"
.ShowOpen
Picture1.Cls
lIcon = ExtractAssociatedIcon(App.hInstance, .FileName, -1)
Call DrawIconEx(Picture1.hdc, 0, 0, lIcon, 32, 32, 0, 0, 3)
End With
User_Cancelled:
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Jan 11th, 2000, 03:17 AM
#3
Thread Starter
Addicted Member
Nice, thanks. That's two in a row you've answered for me ... a human desk reference. Thanks again.
-
Mar 23rd, 2003, 01:17 PM
#4
Lively Member
What if I need to view the icon of an associated file without having the physical file.
Say I have a database loaded with a list of files. I want to load a listview with those files, but they do not exist physically on a disk.
I still want to be able to show the icon next to each item in the list.
Can anyone help me here?
Thanks,
ImpShial
-
Mar 23rd, 2003, 01:27 PM
#5
You could create an empty file with the extension,
extract the icon, then destroy the empty file.
Otherwise you could enumerate the extensions in the HKEY_CLASSES_ROOT Hive of the registry and extract the icons using the icon information stored there.
I've posted many examples in this forum relating to associated file icons,
here's one, it's old, so there are likely better ones I've posted since. (good excuse to use the excellent Search option.)
-
Mar 23rd, 2003, 02:31 PM
#6
Lively Member
Perfect!
Thanks a bunch.
Now I just need to attach this code to a system image list.
Thanks again,
ImpShial
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|