15,980
社区成员




m_imageList.Create(16,16,ILC_COLOR32|ILC_MASK,4,4);
CBitmap b1,b2,b3;
b1.LoadBitmapW(IDB_BITMAP1);
b2.LoadBitmapW(IDB_BITMAP2);
b3.LoadBitmapW(IDB_BITMAP3);
HTREEITEM CDirTreeCtrl::AddItem(HTREEITEM hParent, LPCTSTR strPath)
{// Adding the Item to the TreeCtrl with the current Icons
SHFILEINFO shFinfo;
int iIcon, iIconSel;
CString strTemp = strPath;
if ( strTemp.Right(1) != '\\' ) strTemp += "\\";
if ( !SHGetFileInfo( strTemp,
0,
&shFinfo,
sizeof( shFinfo),
SHGFI_ICON |
SHGFI_SMALLICON))
{
m_strError = "Error Gettting SystemFileInfo!";
return NULL;
}
iIcon = shFinfo.iIcon;
// we only need the index from the system image list
DestroyIcon( shFinfo.hIcon );
if( !SHGetFileInfo( strTemp,
0,
&shFinfo,
sizeof( shFinfo ),
SHGFI_ICON | SHGFI_OPENICON |
SHGFI_SMALLICON))
{
m_strError = "Error Gettting SystemFileInfo!";
return NULL;
}
iIconSel = shFinfo.iIcon;
// we only need the index of the system image list
DestroyIcon( shFinfo.hIcon );
if ( strTemp.Right(1) == "\\" ) strTemp.SetAt( strTemp.GetLength() - 1, '\0' );
if ( hParent == TVI_ROOT ) return InsertItem( strTemp, iIcon, iIconSel, hParent );
return InsertItem( GetSubPath( strTemp ), iIcon, iIconSel, hParent );
}
BOOL CDirTreeCtrl::GetSysImgList()
{
SHFILEINFO shFinfo;
HIMAGELIST hImgList = NULL;
if (GetImageList(TVSIL_NORMAL)) m_imgList.Detach();
hImgList = (HIMAGELIST)SHGetFileInfo( "C:\\",
0,
&shFinfo,
sizeof( shFinfo ),
SHGFI_SYSICONINDEX |
SHGFI_SMALLICON );
if( !hImgList )
{
m_strError = "Cannot retrieve the Handle of SystemImageList!";
return FALSE;
}
m_imgList.m_hImageList = hImgList;
SetImageList( &m_imgList, TVSIL_NORMAL );
return TRUE; // OK
}
BOOL b = find.IsDirectory();
if(b)
{
hItem = m_mytree.m_tree.InsertItem(FileName,1,1,hRoot);//文件夹;
}else
{
hItem = m_mytree.m_tree.InsertItem(FileName,2,2,hRoot);//文件;
}
b1.LoadBitmapW(IDB_BITMAP3);
b2.LoadBitmapW(IDB_BITMAP2);
b3.LoadBitmapW(IDB_BITMAP1);