CString居然不能用加号连串了? cstring 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 刚才发现只有在OnSelchangedTreeDir函数内CString才会出现这种情况,别的地方完全正常。 或许是FindFile参数的问题?finder.FindFile((LPCTSTR)(m_strPath+_T("\\*.*"))) 如果你的m_strPath是用_T("")定义的,不需要用“+”连接,即用_T("")定义的字符可直接连接或用空格分开。 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::Formatstr.Format(_T("%s%s"),m_strPath ,_T("\\*.*")); 找到原因了,原因是目录树控件返回的路径有问题。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;}该死的控件坑死我了,还好有源代码。 我一般都用 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); 急救、急救,关于将VIEW创建的控件消息映射到MAINFRAME,在线等待 VC++的练习题《二胡観音》 如何消除警告--数据类型转换问题 局域网广播 有关修改CListCtrl项的图标问题。 类成员变量可以动态创建吗,如何才能实现 setup.ini ,请求各位帮助!!!!!!!谢谢!!!! Atl 的复合控件,在复合控件的对话框中,将始果得到Edit,Radio的值 关于PDF控件的问题~!要做一个类似Acrobat Distiller5.0的工具 如何在一个页面中刷新另一个页面 这个有点意思的问题,搞不懂为什么 vs2010创建mfc项目的具体步骤
finder.FindFile((LPCTSTR)(m_strPath+_T("\\*.*")))
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("\\*.*"));
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;
}该死的控件坑死我了,还好有源代码。
不管你前后有没有反斜线,以及 . 和 .. 等相对路径,最后都能合成完美的路径。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);