Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17596
  • 博文数量: 34
  • 博客积分: 990
  • 博客等级: 准尉
  • 技术积分: 330
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-31 20:57
文章分类
文章存档

2012年(8)

2011年(26)

我的朋友
最近访客

分类: C/C++

2012-02-09 12:59:17

//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) |
0

上一篇:Messagebox

下一篇:VCToolTip

给主人留下些什么吧!~~