问题描述:
通过按钮选择文件夹,程序遍历选择的文件夹后,怎么将该文件夹下的图片全部以缩略图的形式显示在listcontrol控件中?
我的代码如下:还需添加什么?
//单击“浏览按钮”,获取文件路径,并在编辑控件中显示所选择的文件夹的路径
void Clist_testDlg::OnThrough()
{
//选择文件夹
CString strFolderPath(_T(""));
TCHAR szPath[_MAX_PATH];
BROWSEINFO bi;
bi.hwndOwner = GetSafeHwnd();
bi.pidlRoot = NULL;
bi.lpszTitle = _T("选择文件夹");
bi.pszDisplayName = szPath;
bi.ulFlags = BIF_RETURNONLYFSDIRS|BIF_EDITBOX|BIF_DONTGOBELOWDOMAIN;;//返回一个文件目录
bi.lpfn = NULL;
bi.lParam = NULL;
//bi.iImage = IDR_MAINFRAME;
LPITEMIDLIST pItemIDList = SHBrowseForFolder(&bi);
if (pItemIDList)
{
if (SHGetPathFromIDList(pItemIDList,szPath))
{
strFolderPath = szPath;
//将选择的文件路径在编辑框中显示出来
SetDlgItemText(IDC_EDIT1,strFolderPath);
}
//防止内存泄露,要使用IMalloc接口
IMalloc* pMalloc;
if (SHGetMalloc(&pMalloc) != NOERROR)
{
TRACE(_T("无法取得外壳程序的IMalloc接口\n"));
}
pMalloc ->Free(pItemIDList);
if (pMalloc)
pMalloc ->Release();
}
else
{
strFolderPath = _T(""); //文件夹路径为空
}
ScanDiskFile(strFolderPath);
}
void Clist_testDlg::ScanDiskFile(const CString& strPath)
{
CFileFind find;
CString strTemp = strPath;
CString strDirectory = strPath + _T("\")
+ _T("\*.jpg|*.bmp|*.gif|*.png");
CString strFile;
StringList m_vStrAllFiles;//zm容器
BOOL IsFind = find.FindFile(strDirectory);
while(IsFind)
{
IsFind = find.FindNextFile();
//如果是"."则不扫描
if(find.IsDots())
continue;
//如果是目录,继续扫描此目录
else
if (find.IsDirectory())
{
strFile = find.GetFileName();
strTemp = strTemp + _T("\\")+strFile;
ScanDiskFile(strTemp);
}
//文件
else
{
strFile = find.GetFileName();
m_vStrAllFiles.push_back(strFile);
}
}
find.Close();
}