CSystemImageList::CSystemImageList()
{
if (m_nRefCount == 0)
{
//Attach to the system image list
SHFILEINFO sfi;
HIMAGELIST hSystemImageList = (HIMAGELIST) SHGetFileInfo(_T("\\"), 0, &sfi, sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
VERIFY(m_ImageList.Attach(hSystemImageList));
}
//Increment the reference count
m_nRefCount++;
}
CSystemImageList::~CSystemImageList()
{
//Decrement the reference count
m_nRefCount--;
if (m_nRefCount == 0)
{
//Detach from the image list to prevent problems on 95/98 where
//the system image list is shared across processes
m_ImageList.Detach();
}
}
int CTreeListFileDlg::GetIconIndex(const CString& sFilename)
{
//Retreive the icon index for a specified file/folder
SHFILEINFO sfi;
if (SHGetFileInfo(sFilename, 0, &sfi, sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_SMALLICON) == 0)
return -1;
return sfi.iIcon;
}