有个地方需要实现打开文件夹(图片文件),把所在文件夹下的图片文件名称插入列表框listctrl,帮忙看下我那里有错!我想几好久没做出来!
需要打开的是目录,插入的是文件名称和文件大小。
void CClientDlg::OnButtonOpenFile()
{
// TODO: Add your control notification handler code here
//清空当前列表选项
m_ListCtrl.DeleteAllItems();
static char szFilter[]="(*.BMP) (*.JPG)|*.BMP| |*.JPG|"; //过滤,只显示(*.BMP) (*.JPG)
CFileDialog Dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
if(Dlg.DoModal()!=IDOK)
return;
CFileFind myFindFile;
CString str;
int nIndex;
if (myFindFile.FindFile(Dlg.GetPathName()))
{
while (myFindFile.FindNextFile())
{
if (myFindFile.IsDots())
continue;
str = myFindFile.GetFileName();
nIndex = m_ListCtrl.InsertItem(0,str,0);
}
}
}
需要打开的是目录,插入的是文件名称和文件大小。
void CClientDlg::OnButtonOpenFile()
{
// TODO: Add your control notification handler code here
//清空当前列表选项
m_ListCtrl.DeleteAllItems();
static char szFilter[]="(*.BMP) (*.JPG)|*.BMP| |*.JPG|"; //过滤,只显示(*.BMP) (*.JPG)
CFileDialog Dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
if(Dlg.DoModal()!=IDOK)
return;
CFileFind myFindFile;
CString str;
int nIndex;
if (myFindFile.FindFile(Dlg.GetPathName()))
{
while (myFindFile.FindNextFile())
{
if (myFindFile.IsDots())
continue;
str = myFindFile.GetFileName();
nIndex = m_ListCtrl.InsertItem(0,str,0);
}
}
}
解决方案 »
- 点击对话框的打开图片按钮后,用户可以选择输入bmp格式的图片,并在对话框中的picture显示出来
- 关于VC界面显示多语言问题
- 求教!子对话框怎么调用主对话框的结果记录集?
- 怎样在线程中更新GUI画面的内容???或者是发送消息同志GUI线程去更新??
- 用visual c++6.0能写16位dll么?怎么写?如果不能,用什么写16位dll呢?
- 在dll用MessageBox出现这个错
- CListCtrl的EditLabel问题
- 怎样让被覆盖的对话框再显示?
- 几个小东西,大家写写看,一个25分,第一个写出拿分
- 单文档窗口程序中,如何只保存发生变化的数据?和只在需要时才从文件中读取数据?
- 关于监控系统中的数据库设计
- 那位是vc+oracle高手?
我想知道是如何打开一个文件目录,然后显示在listctrl里面的。
char szDir[MAX_PATH];
BROWSEINFO bi;
ITEMIDLIST *pidl; bi.hwndOwner = this->m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szDir;
bi.lpszTitle = "请选择目录";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0; pidl = SHBrowseForFolder(&bi);
if(pidl == NULL)
return;
if(!SHGetPathFromIDList(pidl, szDir))
return;void ListFolder(CString sPath)
{
CFileFind ff;
BOOL bFound;
bFound = ff.FindFile(sPath + "\\*.*");
while(bFound)
{
bFound = ff.FindNextFile();
CString sFilePath = ff.GetFilePath(); if(ff.IsDirectory())
{
continue;
}
else
{
//记录得到的文件名
}
}
ff.Close();
}
我照猫画虎实现了!