新手跪求高手们给看一下我写的TreeCtrl继承类,检测不出错误但就是有问题??
我写了一个显示 系统图标 的递归显示文件夹和文件的树的继承类,但是使用的时候发现显示速度出奇的慢,不知道为什么?而且显示的图标都是一个共享图标,别的就没有了,Debug也看不出错误,请高手们给我看看,小弟跪谢了
BOOL CDirTreeCtrl::GetSysImgList()//得到系统图标
{
SHFILEINFO shFileInfo;
HIMAGELIST hImgList = NULL;
if(GetImageList( TVSIL_NORMAL ))
m_imgList.Detach();//Detaches an image list object from a CImageList object and returns a handle to an image list
hImgList = (HIMAGELIST)SHGetFileInfo( "C:\\",
0,
&shFileInfo,
sizeof(shFileInfo),
SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
if( !hImgList )
return FALSE;
m_imgList.m_hImageList = hImgList;
SetImageList(&m_imgList,TVSIL_NORMAL);
return TRUE;
}
BOOL CDirTreeCtrl::DisplayTree(HTREEITEM hParent, CString strPath)//递归显示树,
{
CFileFind find;
CString strTemp = strPath;
BOOL bFind;
SHFILEINFO shFinfo;
int iIcon,iIconSel;
HTREEITEM hSubItem;
//DWORD dwStyle = GetStyle();
DeleteAllItems();
if( !GetSysImgList())
return FALSE;
if( strTemp.Right(1) != "\\" )
strTemp += "\\";
strTemp += "*.*";
if(!SHGetFileInfo( strTemp,
0,
&shFinfo,
sizeof( shFinfo ),
SHGFI_ICON|SHGFI_SMALLICON)
)
{
return FALSE;
}
iIcon = shFinfo.iIcon;//正常图标
DestroyIcon( shFinfo.hIcon );
if( !SHGetFileInfo( strTemp,
0,
&shFinfo,
sizeof( shFinfo ),
SHGFI_ICON|SHGFI_OPENICON|
SHGFI_SMALLICON) )
{
return FALSE;
}
iIconSel = shFinfo.iIcon;//打开的图标
DestroyIcon( shFinfo.hIcon );
bFind = find.FindFile( strTemp );
while( bFind )
{
bFind = find.FindNextFile();
if( find.IsDirectory()&&!find.IsDots() )//目录是文件夹
//如果是一个子目录,递归继续往深一层查找
{
CString strPath = find.GetFilePath();//得到路径作为递归调用的开始
CString strTitle = find.GetFileName();//得到目录名
hSubItem = InsertItem( strTitle,0,0,hParent );
DisplayTree( hSubItem,strPath );
}
else if( !find.IsDirectory()&&!find.IsDots() )//到达最底层文件
{
CTime time;
CString strPath;
CString strName;
strPath = find.GetFilePath();
strName = find.GetFileName();
InsertItem( strName,0,0,hParent );
}
}
find.Close();
return TRUE;
}