这是由IShellFolder接口提供的浏览文件夹功能:
void SpecialFolder_Browse(HWND hwnd)
{
LPMALLOC g_pMalloc;
/* Gets the Shell's default allocator */
if (::SHGetMalloc(&g_pMalloc) == NOERROR)
{
BROWSEINFO bi;
LPTSTR lpBuffer;
LPITEMIDLIST pidlSpecialFolder; // PIDL for Special Folder
LPITEMIDLIST pidlBrowse; // PIDL selected by user
// Allocate a buffer to receive browse information.
if ((lpBuffer = (LPTSTR) g_pMalloc->Alloc(MAX_PATH)) != NULL)
{
// Get the PIDL for the Programs folder.
if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_DESKTOP/*CSIDL_DESKTOPDIRECTORY*/ , &pidlSpecialFolder)))
{
// Fill in the BROWSEINFO structure.
bi.hwndOwner = hwnd;
bi.pidlRoot = pidlSpecialFolder;
bi.pszDisplayName = lpBuffer;
bi.lpszTitle = _T("Choose a Program Group");
bi.ulFlags = 0;
bi.lpfn = NULL;
bi.lParam = 0;
// Browse for a folder and return its PIDL.
pidlBrowse = SHBrowseForFolder(&bi);
if (pidlBrowse != NULL)
{
// Show the display name, title, and file system path.
::MessageBox(hwnd, lpBuffer, L"Display name", MB_OK);
if (SHGetPathFromIDList(pidlBrowse, lpBuffer)) //SHGetPathFromIDList获得pidlBrowse的全路径保存在缓存中
MessageBox(lpBuffer);
// Free the PIDL returned by SHBrowseForFolder.
g_pMalloc->Free(pidlBrowse);
}
// Clean up.
g_pMalloc->Free(pidlSpecialFolder);
}
g_pMalloc->Free(lpBuffer);
}
// Release the shell's allocator.
g_pMalloc->Release();
}
}
原文链接:http://blog.csdn.net/zgl7903/article/details/2577729