void SpecialFolder_Browse(HWND hwnd)
{
LPMALLOC g_pMalloc;
/* Gets the Shell's default allocator */
if (::SHGetMalloc(&g_pMalloc) == NOERROR)
{
BROWSEINFO bi;
LPSTR lpBuffer;
LPITEMIDLIST pidlSpecialFolder; // PIDL for Special Folder
LPITEMIDLIST pidlBrowse; // PIDL selected by user
// Allocate a buffer to receive browse information.
if ((lpBuffer = (LPSTR) g_pMalloc->Alloc(MAX_PATH)) != NULL)
{
// Get the PIDL for the Programs folder.
if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_DRIVES , &pidlSpecialFolder)))
{
// Fill in the BROWSEINFO structure.
bi.hwndOwner = hwnd;
bi.pidlRoot = pidlSpecialFolder;
bi.pszDisplayName = lpBuffer;
bi.lpszTitle = "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, "Display name", MB_OK);
if (SHGetPathFromIDList(pidlBrowse, lpBuffer))
SetWindowText(hwnd, 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();
}
}
IShellFolder 接口浏览文件夹(一)
最新推荐文章于 2021-01-17 12:32:51 发布