zoukankan      html  css  js  c++  java
  • MFC读取单个文件/文件名目录/文件目录下所有文件

    1.读取单个文件路径

     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...");
     9     dlg.m_ofn.nMaxFile = MAX_PATH;
    10     if (dlg.DoModal() == IDOK)
    11     {
    12         m_path = dlg.GetPathName();
    13         m_isOpen = TRUE;
    14         UpdateData(FALSE);
    15     }
    16     else
    17         return;
    18     //左边图片控件显示图片
    19     char* s_path;
    20     USES_CONVERSION;
    21     s_path = T2A(m_path);

    2.读取多个文件的文件名

     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.选择文件夹路径

     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
    "));
    26         }
    27 
    28         pMalloc->Free(pItemIDList);
    29         if (pMalloc)
    30             pMalloc->Release();
    31         UpdateData(FALSE);
    32     }
  • 相关阅读:
    特征归一化
    什么是端到端(end2end)学习?
    RSA加密原理及其证明
    python脚本中__all__变量的用法
    洛谷 1108 低价购买
    洛谷 3029 [USACO11NOV]牛的阵容Cow Lineup
    洛谷 1365 WJMZBMR打osu! / Easy
    洛谷 2759 奇怪的函数
    洛谷 2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm
    牛客网NOIP赛前集训营 提高组 第5场 T2 旅游
  • 原文地址:https://www.cnblogs.com/sclu/p/11599499.html
Copyright © 2011-2022 走看看