指定根目录打开windows目录浏览对话框

//获取指定目录的ITEMIDLIST BOOL getPathIDL(HWND hWnd, LPWSTR strPath, LPITEMIDLIST& pIDL) { LPSHELLFOLDER pDesktopFolder; HRESULT hr; if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder))) { __try { hr = pDesktopFolder->ParseDisplayName(hWnd, NULL, strPath, NULL, &pIDL, NULL); if (FAILED(hr)) { return FALSE; } // // pidl now contains a pointer to an ITEMIDLIST for ./readme.txt. // This ITEMIDLIST needs to be freed using the IMalloc allocator // returned from SHGetMalloc(). // return TRUE; } __finally { pDesktopFolder->Release(); } } return FALSE; } void CDiskCleanDlg::OnBnClickedChdir() { // TODO: 在此添加控件通知处理程序代码 int nCurSel = m_ctlComboDrive.GetCurSel(); if (nCurSel == CB_ERR) { return; } CString strPath; m_ctlComboDrive.GetLBText(nCurSel, strPath); IMalloc* pMalloc; HRESULT hr; //获取IMalloc接口 hr = SHGetMalloc(&pMalloc); if (FAILED(hr)) { return ; } LPITEMIDLIST pIDL; if (!getPathIDL(m_hWnd, strPath.GetBuffer(), pIDL)) { return ; } wchar_t buff[1024] = {0}; BROWSEINFO bi; ZeroMemory(&bi, sizeof(bi)); bi.hwndOwner = m_hWnd; bi.pidlRoot = pIDL; bi.pszDisplayName = buff;//这里不能获取全路径 bi.lpszTitle = _T("请选择子目录"); bi.ulFlags = BIF_RETURNONLYFSDIRS; LPITEMIDLIST pPathIDL = SHBrowseForFolder(&bi); if (pPathIDL == NULL) { return ; } buff[0] = 0; if (SHGetPathFromIDList(pPathIDL, buff)) { m_strPath = buff; if (m_strPath.Right(1) != "//") { m_strPath += "//"; } UpdateData(FALSE); } pMalloc->Free(pPathIDL); }

 

你可能感兴趣的:(windows,null,BI)