//caller
void OpenFolder()
{
BROWSEINFOW binfo = {};
TCHAR strName[MAX_PATH] = {};
binfo.hwndOwner = m_hWnd;
binfo.pszDisplayName = strName;
binfo.pidlRoot = ConventIdlFromPath(_T(""));
binfo.lpfn = BrowseCallbackProc;
TCHAR Path[MAX_PATH] = {};
SHGetPathFromIDList(SHBrowseForFolder(&binfo), Path);
return;
}
//Set init folder
INT CALLBACK BrowseCallbackProc(HWND hwnd,
UINT uMsg,
LPARAM lp,
LPARAM pData)
{
TCHAR szDir[MAX_PATH];
switch(uMsg)
{
case BFFM_INITIALIZED:
if (GetCurrentDirectory(sizeof(szDir)/sizeof(TCHAR), szDir))
{
// WParam is TRUE since you are passing a path.
// It would be FALSE if you were passing a pidl.
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDir);
}
break;
case BFFM_SELCHANGED:
// Set the status window to the currently selected path.
if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szDir))
{
SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir);
}
break;
}
return 0;
}
//Root firectory
LPITEMIDLIST ConventIdlFromPath( LPCTSTR szPath )
{
CString strPath(szPath);
static LPITEMIDLIST pidl;
LPSHELLFOLDER pDesktopFolder;
//char szPath[MAX_PATH];
//OLECHAR olePath[MAX_PATH];
ULONG chEaten;
ULONG dwAttributes;
HRESULT hr;
//olePath = T2OLE(strPath.GetBuffer());
//
// Get the path to the file we need to convert.
//
//GetCurrentDirectory(MAX_PATH, szPath);
//lstrcat(szPath, "\\readme.txt");
//
// Get a pointer to the Desktop's IShellFolder interface.
//
if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
{
//
// IShellFolder::ParseDisplayName requires the file name be in
// Unicode.
//
//MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szPath, -1,
// olePath, MAX_PATH);
//
// Convert the path to an ITEMIDLIST.
//
hr = pDesktopFolder->ParseDisplayName(m_hWnd,
NULL,
strPath.GetBuffer(MAX_PATH),
&chEaten,
&pidl,
&dwAttributes);
if (FAILED(hr))
{
VERIFY(NULL);
// Handle error.
}
strPath.ReleaseBuffer(-1);
//
// pidl now contains a pointer to an ITEMIDLIST for .\readme.txt.
// This ITEMIDLIST needs to be freed using the IMalloc allocator
// returned from SHGetMalloc().
//
//release the desktop folder object
pDesktopFolder->Release();
}
return pidl;
}
ref link:
阅读(171) | 评论(0) | 转发(0) |