解决方案 »

  1.   

    刚才发现只有在OnSelchangedTreeDir函数内CString才会出现这种情况,别的地方完全正常。
      

  2.   

    或许是FindFile参数的问题?
    finder.FindFile((LPCTSTR)(m_strPath+_T("\\*.*")))
      

  3.   

    如果你的m_strPath是用_T("")定义的,不需要用“+”连接,即用_T("")定义的字符可直接连接或用空格分开。
      

  4.   

    m_strPath定义的类型是什么,应该不是CString吧,如果m_strPath不是CString ,那这一句
    CString str = m_strPath + _T("\\*.*");
    等号的右边的运算与CString无关,你可以把m_strPath定义成CString,或者把m_strPath强制转换成CString,你下面这样
    CString str = (CString)m_strPath + _T("\\*.*");
    -------------------------------------
    最后建议用CString::Format
    str.Format(_T("%s%s"),m_strPath ,_T("\\*.*"));
      

  5.   

    找到原因了,原因是目录树控件返回的路径有问题。
    if ( strReturn.Right(1) == '\\' ) strReturn.SetAt(strReturn.GetLength() - 1, 0);
    目的是要去掉最后一个'\',但是这样做字符串长度不会减少。
    CString AFXAPI operator+(const CString& string, LPCTSTR lpsz)
    {
    ASSERT(lpsz == NULL || AfxIsValidString(lpsz));
    CString s;
    s.ConcatCopy(string.GetData()->nDataLength, string.m_pchData,
    CString::SafeStrlen(lpsz), lpsz);
    return s;
    }该死的控件坑死我了,还好有源代码。
      

  6.   

    我一般都用 PathAppend 和 PathCombine 之类的 API 来处理路径。
    不管你前后有没有反斜线,以及 . 和 .. 等相对路径,最后都能合成完美的路径。CString strFilter;
    // 前面末尾可以有或没有 \ 结尾,后面可以是 *.*、.\\*.*、.\\.\\*.* 不管怎么样都行。
    ::PathCombine(strFilter.GetBuffer(MAX_PATH), m_strPath.GetBuffer(MAX_PATH), _T("*.*"));
    strFilter.ReleaseBuffer();
    m_strPath.ReleaseBuffer();
    BOOL bFind = finder.FindFile(strFilter);// 修改现有字符串
    ::PathAppend(m_strPath.GetBuffer(MAX_PATH), _T("*.*"));
    m_strPath.ReleaseBuffer();
    BOOL bFind = finder.FindFile(m_strPath);