/********************************************************************
created: 2008/04/24
created: 24:4:2008 12:47
author: Gohan
http://feed.feedsky.com/gohan
purpose: 演示SHBrowseForFolder用法
*********************************************************************/
#include <Windows.h>
#include <ShlObj.h>
int main()
{
BROWSEINFO bi;
ZeroMemory(&bi,sizeof(BROWSEINFO));
LPMALLOC pMalloc;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
TCHAR * path = new TCHAR[MAX_PATH];
if(pidl != NULL)
{
SHGetPathFromIDList(pidl,path);
MessageBox(NULL,path,TEXT("Choose"),MB_OK);
if(SUCCEEDED(SHGetMalloc(&pMalloc)))//pidl指向的对象用完应该释放,之前忽略了
{
pMalloc->Free(pidl);
pMalloc->Release();
}
}
else
{
MessageBox(NULL,TEXT("选择为空"),TEXT("Choose"),MB_OK);
}
delete path;//谢谢true的提醒,以后我一定会更加慎重
}