获取文件路径
//此函数得到所选文件的路径
BOOL GetDirectoryPath(
LPTSTR szPathBuffer,
DWORD dwBufferSize,
HWND hWnd = NULL,
LPCTSTR szTitle = _T("选择一个文件夹"))
{
//定义文件夹的路径
//定义指向IMalloc的指针
LPMALLOC pMalloc;
if(SHGetMalloc(&pMalloc) != NOERROR)
return FALSE;
TCHAR szDisplayName[_MAX_PATH];
TCHAR szBuffer[_MAX_PATH];
BROWSEINFO BrowseInfo;
BrowseInfo.hwndOwner = hWnd;
BrowseInfo.pidlRoot = NULL;
BrowseInfo.pszDisplayName = szDisplayName;
BrowseInfo.lpszTitle = szTitle;
BrowseInfo.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
BrowseInfo.lpfn = NULL;
BrowseInfo.lParam = 0;
LPITEMIDLIST lpItemIDList;
if((lpItemIDList = SHBrowseForFolder(&BrowseInfo)) != NULL)
{
//得到
if(SHGetPathFromIDList(lpItemIDList,szBuffer))
{
if(szBuffer[0] == _T('\0'))return FALSE;
if(!szPathBuffer)return FALSE;
_tcscpy_s(szPathBuffer,dwBufferSize,szBuffer);
return TRUE;
}
else
{
return FALSE;
}
pMalloc->Free(lpItemIDList);
pMalloc->Release();
}
return FALSE;
}
BOOL GetDirectoryPath(
LPTSTR szPathBuffer,
DWORD dwBufferSize,
HWND hWnd = NULL,
LPCTSTR szTitle = _T("选择一个文件夹"))
{
//定义文件夹的路径
//定义指向IMalloc的指针
LPMALLOC pMalloc;
if(SHGetMalloc(&pMalloc) != NOERROR)
return FALSE;
TCHAR szDisplayName[_MAX_PATH];
TCHAR szBuffer[_MAX_PATH];
BROWSEINFO BrowseInfo;
BrowseInfo.hwndOwner = hWnd;
BrowseInfo.pidlRoot = NULL;
BrowseInfo.pszDisplayName = szDisplayName;
BrowseInfo.lpszTitle = szTitle;
BrowseInfo.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
BrowseInfo.lpfn = NULL;
BrowseInfo.lParam = 0;
LPITEMIDLIST lpItemIDList;
if((lpItemIDList = SHBrowseForFolder(&BrowseInfo)) != NULL)
{
//得到
if(SHGetPathFromIDList(lpItemIDList,szBuffer))
{
if(szBuffer[0] == _T('\0'))return FALSE;
if(!szPathBuffer)return FALSE;
_tcscpy_s(szPathBuffer,dwBufferSize,szBuffer);
return TRUE;
}
else
{
return FALSE;
}
pMalloc->Free(lpItemIDList);
pMalloc->Release();
}
return FALSE;
}