打开文件夹获得图片路径

 主要使用CFileDialog类实现:

// void ReadSource()

[cpp]  view plain  copy
 print ?
  1. void ReadSource()  
  2. {  
  3.     CFileDialog ccFileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,   
  4.         _T("Image files(*.png; *.jpg)|*.png;*.jpg|All files(*.*)|*.*||"), NULL);  
  5.     if (ccFileDlg.DoModal() == IDOK)  
  6.     {  
  7.         CString strPathName = ccFileDlg.GetPathName();  
  8.         CString strDir = strPathName.Left(strPathName.ReverseFind('\\'));  
  9.         ReadFile(strDir))  
  10.           
  11.     }  
  12. }  

// void ReadFile(const CString& strPath)

[cpp]  view plain  copy
 print ?
  1. bool ReadFile(const CString& strPath)  
  2. {  
  3.     CFileFind ccFileFind;  
  4.     CString strTemp = strPath;  
  5.     CString strDir = strPath + _T("\\") + _T("*.*");  
  6.     CString strFile;  
  7.   
  8.     BOOL bFind = ccFileFind.FindFile(strDir);  
  9.     while (bFind)  
  10.     {  
  11.         bFind = ccFileFind.FindNextFile();  
  12.         if (ccFileFind.IsDots())  
  13.         {  
  14.             // 如果是".",则不扫描  
  15.             continue;  
  16.         }  
  17.         else if (ccFileFind.IsDirectory())  
  18.         {  
  19.             // 如果是目录,则继续扫描  
  20.             strFile = ccFileFind.GetFileName();  
  21.             strTemp = strTemp + _T("\\") + strFile;  
  22.             this->ReadFile(strTemp);  
  23.         }  
  24.         else  
  25.         {  
  26.             // 如果是资源文件,则存储  
  27.             //strFile = ccFileFind.GetFileName();  
  28.             strFile = ccFileFind.GetFilePath();   
  29.             m_vecResDirData.push_back(str);  // std::vector<CString> m_vecResDirData  
  30.         }  
  31.     }  
  32.     ccFileFind.Close();  
  33.     return true;  
  34. }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值