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     }
  • 相关阅读:
    scrapy怎么设置带有密码的代理ip base64.encodestring不能用 python3.5,base64库里面的encodestring()被换成了什么?
    ace模板dataTables_length控制是否显示分页
    Django AUTHENTICATION_BACKENDS
    Django自定义User模型和登录验证
    一个简单的django user.is_authenticated问题
    PHP函数(四)-变量函数
    PHP函数(三)-递归函数
    Python多进程
    Python多线程-生产者消费者模型
    Python多线程-队列
  • 原文地址:https://www.cnblogs.com/sclu/p/11599499.html
Copyright © 2011-2022 走看看