MFC read all the files in a single file / directory name / file directory

1. Read a single file path

 1 Invalidate();
 2 
 3     CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_READONLY,
 4         TEXT("Supported Types (*.jpg;*.png;*.gif;*.bmp;...)|*.jpg;*.png;*.gif;*.bmp|Tiff(*.tiff;*.tif)|*.tiff;*.tif|All Files(*.*)|*.*||"), NULL);
 5     dlg.m_ofn.nFilterIndex = 1;
 6     dlg.m_ofn.hwndOwner = m_hWnd;
 7     dlg.m_ofn.lStructSize = sizeof(OPENFILENAME);
 8     dlg.m_ofn.lpstrTitle = TEXT("Opening Image...\0");
 9     = dlg.m_ofn.nMaxFile the MAX_PATH;
 10      IF (dlg.DoModal () == IDOK)
 . 11      {
 12 is          m_Path = dlg.GetPathName ();
 13 is          m_isOpen = TRUE;
 14          UpdateData (FALSE);
 15      }
 16      the else 
. 17          return ;
 18 is      // picture on the left controls the display picture 
19      char * S_PATH;
 20      USES_CONVERSION;
 21      S_PATH = T2A (m_path);

 

2. read multiple file name

 1    vector<CString>fileDict;
     CFileDialog dlg(TRUE, _T("*"), NULL, OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST, _T("所有文件 file (*.*)|*.*||"), NULL); 2 DWORD MAXFILE = 500 * MAX_PATH;// 最多打开500个文件 3 dlg.m_ofn.nMaxFile = MAXFILE; 4 TCHAR* buf = new TCHAR[MAXFILE]; 5 memset(buf, 0, sizeof(TCHAR) * MAXFILE); 6 dlg.m_ofn.lpstrFile = buf; 7 8 int iReturn = dlg.DoModal(); 9 if (iReturn == IDCANCEL) 10 { 11 return; 12 } 13 POSITION pos = dlg.GetStartPosition(); 14 while (pos != NULL) 15 { 16 fileDict.push_back(dlg.GetNextPathName(pos)); 17 } 18 19 delete[] buf;
    }

 

 

3. Select the folder path

 1 CString m_saveFilePath;
 2     TCHAR szPath[_MAX_PATH];
 3     BROWSEINFO bi;
 4     bi.hwndOwner = GetSafeHwnd();
 5     bi.pidlRoot = NULL;
 6     bi.lpszTitle = _T("请选择图片路径");
 7     bi.pszDisplayName = szPath;
 8     bi.ulFlags = BIF_RETURNONLYFSDIRS;
 9     bi.lpfn = NULL;
10     bi.lParam = NULL;
11 
12     LPITEMIDLIST pItemIDList = SHBrowseForFolder(&bi);
13     if (pItemIDList)
14     {
15         if (SHGetPathFromIDList(pItemIDList, szPath))
16         {
17             m_saveFilePath = szPath;
18             m_saveFilePath = m_saveFilePath + _T("\\");
19         }
20 
21         //use IMalloc interface for avoiding memory leak  
22         IMalloc* pMalloc;
23         if (SHGetMalloc(&pMalloc) != NOERROR)
24         {
25             TRACE(_T("Can't get the IMalloc interface\n"));
26         }
27 
28         pMalloc->Free(pItemIDList);
29         if (pMalloc)
30             pMalloc->Release();
31         UpdateData(FALSE);
32     }

 

Guess you like

Origin www.cnblogs.com/sclu/p/11599499.html