就是能支持多个选中文件,并且只要选中到路径,把当前的路径取出来。把它赋值到数组里。紧急等待中

解决方案 »

  1.   

    以下这段代码希望对你有帮助
       CFileDialog   dlg( TRUE, NULL, NULL, OFN_ALLOWMULTISELECT, NULL, NULL );
       DWORD MAXFILE = 2562; //2562 is the max
       dlg.m_ofn.nMaxFile = MAXFILE;
       char* pc = new char[MAXFILE];
       dlg.m_ofn.lpstrFile = pc;
       dlg.m_ofn.lpstrFile[0] = NULL;   int iReturn = dlg.DoModal();
       if(iReturn ==  IDOK)
       {
          int nCount = 0;
          POSITION pos = dlg.GetStartPosition();
          while (pos != NULL)
          {
             Cstring tmp = dlg.GetNextPathName(pos);
     Cstring fn = dlg.GetPathName(); 
     long l = fn.GetLength();
     long I = tmp.GetLength();
     fn = tmp.Right(I - l - 1);
     char * szbuf;
     Cfile* pFile = NULL;
     Cfile* pFile1 = NULL;
     pFile = new Cfile(_T(tmp),Cfile::modeRead | Cfile::shareDenyNone);
     fn = "c:\\" + fn;
     pFile1 = new Cfile(_T(fn),Cfile::modeWrite | Cfile::modeCreate);
         ULONGLONG dwLength = pFile->GetLength();
     szbuf = new char[dwLength];
    pFile->Read(szbuf,dwLength);
    pFile1->Write(szbuf,dwLength);
     if (pFile != NULL)   {
      pFile->Close();
      delete pFile;
       }
    if (pFile1 != NULL)   {
      pFile1->Close();
      delete pFile1;
       }         nCount++;
          }
          Cstring str;
          str.Format("Successfully opened %d files\n", nCount);
          AfxMessageBox(str);
       }
       else if(iReturn == IDCANCEL)
          AfxMessageBox("Cancel");
    delete pc;