Tuesday, January 22, 2008

Geting Icons From Shell VC++

SHGetFileInfo function
Retrieves information about an object in the file system, such as a file, folder,directory, or drive root.

With the help of this function we can Get Shell Icon from local system.

Example Source:

#include "shellapi.h"
HICON GetSmallIconFromShell(const CString& strExtension)
{
       HICON hIcon = NULL;
       //Fill with 0
       SHFILEINFO psfi = {0};
       DWORD_PTR ptr = SHGetFileInfo(strExtension,NULL, &psfi,sizeof( psfi ), SHGFI_TYPENAME | SHGFI_ICON |SHGFI_SMALLICON |SHGFI_USEFILEATTRIBUTES);
       if( NULL != ptr)
       {
              hIcon = psfi.hIcon;
       }
       return hIcon;
}

For inserting into image list
nImageIndex = m_pTreeImageList->Add(GetSmallIconFromShell(_T(“.Sen”)));

 

No comments: