mfc 选择文件(可多选)

CFileDialog dlg( TRUE, NULL, NULL, OFN_ALLOWMULTISELECT, NULL, NULL );
    DWORD MAXFILE = 2562; //2562 is the max
    TCHAR* pc = new TCHAR[MAXFILE * (MAX_PATH + 1) + 1];
    pc[0] = pc[1] = 0;
    dlg.m_ofn.nMaxFile = MAXFILE;
    dlg.m_ofn.lpstrFile = pc;

    int iReturn = dlg.DoModal();
    if(iReturn ==  IDOK){
        vFiles.clear();
        int nCount = 0;
        POSITION pos = dlg.GetStartPosition();
        while (pos != NULL){
            CString szPathName = dlg.GetNextPathName(pos);
            wstring s = szPathName.GetString();
            WCHAR *pExtension = PathFindExtension(s.c_str());
            if (pExtension){
                if (_wcsicmp(pExtension, L".bmp") == 0 || _wcsicmp(pExtension, L".jpg") == 0 || _wcsicmp(pExtension, L".png") == 0){
                    vFiles.push_back(s);
                    nCount++;
                }
            }
        }
    }
    else if(iReturn == IDCANCEL){

    }
    delete []pc;

 

posted @ 2015-09-19 09:39  QQ76211822  阅读(582)  评论(0编辑  收藏  举报