Loading

SHBrowseForFolder

转载 演示SHBrowseForFolder用法

/********************************************************************
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;
}
posted @ 2012-08-09 13:31  wswind  阅读(271)  评论(0编辑  收藏  举报