我有 SHBrowseForFolder 弹出并工作正常,但我想设置标题。我知道它必须是 wchar_t* 并且当我使用像 (wchar_t*)L"My Title" 这样的 const 时,标题显示正确。
但是如果我尝试使用字符串值,我只会得到第一个字母“M”,就像宽字符串再次转换为新的宽字符串一样,用 nul 填充每个字符。
Winapi::Shlobj::BROWSEINFO bi = {0};
bi.hwndOwner = Handle;
bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX | BIF_BROWSEFORCOMPUTER;
bi.lpszTitle = String("My Title").w_str(); // This only shows the 'M'
//bi.lpszTitle = (wchar_t*)"My Title"; // This shows the full string 'My Title'
LPITEMIDLIST pidl = SHBrowseForFolder((_browseinfoA*)&bi);
if ( pidl != 0 ) {
// free memory used
IMalloc *imalloc = 0;
if (SUCCEEDED(SHGetMalloc(&imalloc))) {
imalloc->Free(pidl);
imalloc->Release();
}
}
UnicodeString的所有转换函数的文档c_str()
,t_str()
都w_str()
返回一个wchar_t*
但声明显示WideChar*
。
任何想法如何使此代码与字符串一起工作?