Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Getting a file types icon

This topic is 6267 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would one get the icon of a particular file type like in ''My Computer''. I have a list box with a list of files of various extensions, and I need to get the file-type icon and specify the icon when the ListBox item is inserted. For example if I had a BMP file to add to the listbox, the icon would be the icon with the shapes and brush.

  Downloads:  ZeroOne Realm

Share this post

Link to post
Share on other sites
Look in HKEY_CLASSES_ROOT in the registry. The ".bmp" key will have a value (Default) which is the name of another key in HKEY_CLASSES_ROOT. Look in there and you'll find another key named "Default Icon". The (Default) value in there is the name of the icon (the path + the icon's number in that file).

You can use ExtractIcon to get the handle of the icon (HICON) from that file.

[Resist Windows XP's Invasive Production Activation Technology!]

Edited by - Null and Void on September 21, 2001 1:26:31 AM

Share this post

Link to post
Share on other sites
Programmatically, you''ll need to use SHGetFileInfo( most of these ''shell'' type functions begin with SH.. helpful for MSDN searching )...

Here is a code snippet:

ZeroMemory( &stInfo, sizeof( SHFILEINFO ) );

//--Lets get the HICON, as well as the location info..
// Note that you are responsible for cleaning up the HICON
// with DestroyIcon( HICON ), after you have used it..
// ie, you''re done drawing...
if( SHGetFileInfo( "c:\\bug.txt", 0, &stInfo,
//--Let''s display the icon...
m_staticImage.SetIcon( stInfo.hIcon );

m_staticImage is a CStatic object. If you wanted to display in a list ctrl, you''d need to create an image list..

Hope that is helpful..


"It''s only after you''ve lost everything that you''re free to do anything." Tyler Durden

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!