我有个文件夹,我想利用树形控件将此文件夹中的各种文档显示在树形控件里,请问具体代码是什么啊?谢谢了!!
解决方案 »
- wtl项目CWTLClock2View::OnTimer : function does not take 1 arguments 出错
- IWebBrowser2::navigate 不成功,错误代码0x800700aa:请求资源在使用中
- Goto桌面搜索软件
- 如何自己创建一个视图窗口,在线等待,解决马上结贴
- 关于对象变量释放问题,在线等待
- 谁有visual assist 6.0 1077 ?给链接也行。
- 线程同步问题(关于Mutex)!
- 微软管理服务的程序哪位知道叫什么名字?
- 谁有softice的中文说明书?谁能教我用softice?(搜索过以前的文章,发现没用)
- 高分的简单问题:如何设定双重代理?
- 用钩子处理listbox消息出问题
- 高分求ftp源码!
用CFileFind 在文件夹下查找文件,然后插入到树中
{
// TODO: Add extra initialization here
/*初始化*/
//图标数组
HICON hIcon[4];
hIcon[0]=AfxGetApp()->LoadIcon(IDI_CLOSE);
hIcon[1]=AfxGetApp()->LoadIcon(IDI_OPEN);
hIcon[2]=AfxGetApp()->LoadIcon(IDI_DRIVE);
hIcon[3]=AfxGetApp()->LoadIcon(IDI_FILE); //图标列表
m_imagelist.Create(16, 16, ILC_COLOR32| ILC_MASK, 4, 4);
m_imagelist.Add(hIcon[0]);
m_imagelist.Add(hIcon[1]);
m_imagelist.Add(hIcon[2]);
m_imagelist.Add(hIcon[3]);
//控件指针
CTreeCtrl * pTreeCtrl=(CTreeCtrl *)GetDlgItem(IDC_TREE1);
pTreeCtrl->SetImageList(&m_imagelist,TVSIL_NORMAL);
//树结点
HTREEITEM hRoot;
hRoot=pTreeCtrl->InsertItem(_T("D:"),2,2,NULL);
//递归遍历目录
BrowseDir( "d:", hRoot); return TRUE; // return TRUE unless you set the focus to a control
}void CMyControlDlg::BrowseDir( CString strDir ,HTREEITEM hParent )
{
CFileFind fileFind;
CString szDir = strDir;
HTREEITEM hChild;
CTreeCtrl * pTreeCtrl=(CTreeCtrl *)GetDlgItem(IDC_TREE1); if(szDir.Right(1) != "\\")
{
szDir += "\\";
}
szDir += "*.*";
BOOL res = fileFind.FindFile(szDir); while( res )
{ res = fileFind.FindNextFile();
if(fileFind.IsDirectory() && !fileFind.IsDots())
{
CString strPath = fileFind.GetFilePath();
CString strFileName = fileFind.GetFileName();
hChild = pTreeCtrl->InsertItem(strFileName,0,0,hParent);
BrowseDir( strPath, hChild );
}
else if(!fileFind.IsDirectory() && !fileFind.IsDots())
{
CString strFileName = fileFind.GetFileName();
pTreeCtrl->InsertItem(strFileName,3,3,hParent);
}
} fileFind.Close();
}