This is a VB6 static (.BAS) module containing one function: GetAssocIcon().
You pass it a relative or absolute file name, and whether you want a large (32x32) or small (16x16) icon.
For .ico files you get back the icon.
For programs you get back the program icon (as displayed in Explorer).
For data files, documents, etc. you get back the default program's icon.
You can also pass it an extension alone, as in ".txt" to get the associated program's icon.
The icon is returned as a StdPicture (Picture) object, for easy use in native-VB operations such as adding it to an ImageList control, Image control, etc.
It will almost certainly work in VB5 as well, but I haven't tried that. There should be no special requirements such as a Windows version or any extra dependencies.
Unlike examples based on ExtractAssociatedIcon() calls, this one offers both the large and small icon formats.
The attachment contains a small demo project.
Last edited by dilettante; Aug 7th, 2011 at 01:08 PM.
Reason: Reposted attachment, no-DestroyIcon version