BOOL GetFolderName(HWND hwnd, CString& strFolder)
{
BOOL bRet;
LPMALLOC pMalloc;
bRet = FALSE;
// Gets the Shell's default allocator
if (SHGetMalloc(&pMalloc) == NOERROR)
{
BROWSEINFO bi;
LPITEMIDLIST pidl;
TCHAR pszBuffer[MAX_PATH];
ZeroMemory(pszBuffer, sizeof(pszBuffer));
bi.hwndOwner = hwnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("请选择文件夹:");
bi.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
if ((pidl = SHBrowseForFolder(&bi)) != NULL)
{
SHGetPathFromIDList(pidl, pszBuffer);
strFolder = pszBuffer;
pMalloc->Free(pidl);
bRet = TRUE;
}
pMalloc->Release();
}
return bRet;
}