在选择单个文件的时候没有问题,当选择多个文件的时候GetFileTitle 函数返回的是空值,为何?

解决方案 »

  1.   

    If m_ofn.Flags has the OFN_ALLOWMULTISELECT flag set, this string contains a sequence of null-terminated strings, with the first string being the directory path of the file group selected, followed by the names of all files selected by the user. For this reason, use the GetStartPosition and GetNextPathName member functions to retrieve the next file name in the list.
      

  2.   

    给个例子你参考一下!void OpenFile()
    {
            char buf[8192]; //8K 的缓存
    buf[0]=0;
    CFileDialog dlg(true); dlg.m_ofn.Flags =OFN_ENABLEHOOK | OFN_EXPLORER
    | OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_ALLOWMULTISELECT;
    dlg.m_ofn.lpstrFilter = _T("BMP FILE(*.bmp)\0*.bmp\0");
    dlg.m_ofn.nMaxFile = 8192;
    dlg.m_ofn.lpstrFile=buf;
    if (dlg.DoModal() == IDCANCEL) return; //加入文件
    m_sFileAry.RemoveAll();
    CString filename;
    POSITION pos=dlg.GetStartPosition();
    while(pos!=NULL)
    {
    filename=dlg.GetNextPathName(pos);
    m_sFileAry.Add(filename);
    }
    }
      

  3.   

    那个是MSDN 里的原话嘛,我需要个例子,三楼的没有涉及到GetFileTitle函数哦,我问的是这个函数。不过还是谢谢大家的。
      

  4.   

    要自己对GetNextPathName得到的字符串进行解析
    int npos = FileName.ReverseFind('.');
    int pos = FileName.ReverseFind('\\');
    CString strFileTitle = FileName.Mid(pos+1,npos - pos-1);