CString str1;
CStringA str;
LPITEMIDLIST pidl;
LPMALLOC pShellMalloc;
if (SUCCEEDED(&pShellMalloc))
{
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL,CSIDL_PERSONAL,&pidl)))
{
if(SHGetPathFromIDList(pidl,str1.GetBuffer(MAX_PATH)))
{
str1.ReleaseBuffer(MAX_PATH);
//MessageBox(L"我的文档所在的文件夹所在的位置为位于:\n "+str1,L"信息提示",MB_OK);
}
else
str1.ReleaseBuffer(MAX_PATH);
}
}
//添加微信文件夹
str=str1;
str+="\\WeChat Files";
str1+="\\WeChat Files";
str1.Insert(str1.GetLength(),L"\\WeChat Files\\");
str1.Empty();
CStringA str;
LPITEMIDLIST pidl;
LPMALLOC pShellMalloc;
if (SUCCEEDED(&pShellMalloc))
{
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL,CSIDL_PERSONAL,&pidl)))
{
if(SHGetPathFromIDList(pidl,str1.GetBuffer(MAX_PATH)))
{
str1.ReleaseBuffer(MAX_PATH);
//MessageBox(L"我的文档所在的文件夹所在的位置为位于:\n "+str1,L"信息提示",MB_OK);
}
else
str1.ReleaseBuffer(MAX_PATH);
}
}
//添加微信文件夹
str=str1;
str+="\\WeChat Files";
str1+="\\WeChat Files";
str1.Insert(str1.GetLength(),L"\\WeChat Files\\");
str1.Empty();
str1=str;
小结:CString的变量,加的是位置文件的变量是,用相加,还是插入到结尾都无法完成,只用用CStringA的变量接可以轻松解决,让CString的变量获取CStringA的变量值或很容易的多。