文件夹选择对话框

 

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;
}

 

posted @ 2015-04-15 12:40  huhu0013  阅读(259)  评论(0编辑  收藏  举报