FAQ : Platform Support (Linux, Windows) : Q: How can I get the default Windows application icon for any given file?
Q: How can I get the default Windows application icon for any given file?
Problem
VA Smalltalk contains the method OSHinstance >>extractAssociatedIcon: lpIconPath lpiIcon: lpiIcon but there are no senders of it or documentation on how to use it.
Solution
This code snippet shows how to use the method to obtain the icon associated with a file. You can refer to the MSDN article ExtractAssociatedIcon function for further details.
| modHandle iconHandle iconPath iconIndex icon|
 
modHandle := OSHmodule getModuleHandle: nil. "nil means my .exe"
iconPath:= 'd:\vamgr\inst\uninst.exe'. "We'll get the icon of this file"
iconIndex := ByteArray new: 4.
iconHandle := modHandle extractAssociatedIcon: iconPath asPSZ lpiIcon: iconIndex.
iconHandle ifNotNil: [ icon := CgIcon fromOSIcon: iconHandle ].
 
(Array with: icon with: iconPath with: iconIndex) inspect "Let's see what we got"
 
"Remember to destroy the icon when you're finished with it -- iconhandle destroyIcon"
 
Last modified date: 01/29/2015