怎样调出 SHELL 中的路径选择对话框、、、??

TimiXu 2004-07-02 07:46:26
BROWSEINFO bi;
::ZeroMemory(&bi,sizeof(bi));
TCHAR szSelPath[MAX_PATH];
bi.pszDisplayName = szSelPath;
bi.lpszTitle= "title";
bi.ulFlags=BIF_RETURNONLYFSDIRS|
BIF_EDITBOX |
// BIF_RETURNFSANCESTORS|
BIF_STATUSTEXT|
BIF_VALIDATE;
LPITEMIDLIST pidl=::SHBrowseForFolder(&bi);
if(pidl!=NULL)
{
AfxMessageBox(bi.pszDisplayName);///////////
IMalloc* pMalloc = NULL;
::SHGetMalloc(&pMalloc);
pMalloc->Free(pidl);
pidl = NULL;
pMalloc->Release();
pMalloc=NULL;
}
这样得到只有一个文件夹名,没有得到完整的路径,??
急。
...全文
180 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunsfq 2004-07-02
  • 打赏
  • 举报
回复
/**************************************************
*DirDlg_strPath 若返回1则它保存被选中的目录文件
*DirDlg_strTitle 对话框显示的标题标题
*DirDlg_strInitDir 初始目录,若为NULL则从桌面开始
**************************************************/
int dirDlg(CString *DirDlg_strPath, CString *DirDlg_strTitle, CString *DirDlg_strInitDir, int DirDlg_iImageIndex=0)
{
LPMALLOC pMalloc;
if (SHGetMalloc (&pMalloc)!= NOERROR)
{
return 0;
}

BROWSEINFO bInfo;
LPITEMIDLIST pidl;
ZeroMemory ( (PVOID) &bInfo,sizeof (BROWSEINFO));

if (!DirDlg_strInitDir->IsEmpty ())
{
OLECHAR olePath[MAX_PATH];
ULONG chEaten;
ULONG dwAttributes;
HRESULT hr;
LPSHELLFOLDER pDesktopFolder;
// // 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, DirDlg_strInitDir->GetBuffer (MAX_PATH), -1,
olePath, MAX_PATH);

DirDlg_strInitDir->ReleaseBuffer (-1);
//
// Convert the path to an ITEMIDLIST.
//
hr = pDesktopFolder->ParseDisplayName(NULL,
NULL,
olePath,
&chEaten,
&pidl,
&dwAttributes);
if (FAILED(hr))
{
pMalloc ->Free (pidl);
pMalloc ->Release ();
return 0;
}
bInfo.pidlRoot = pidl;
}
}
bInfo.hwndOwner = NULL;
bInfo.pszDisplayName = DirDlg_strPath->GetBuffer (MAX_PATH);
bInfo.lpszTitle = (DirDlg_strTitle->IsEmpty()) ? "????????????!":*DirDlg_strTitle;
bInfo.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS;


if ((pidl = ::SHBrowseForFolder (&bInfo)) == NULL)
{
return 0;
}
DirDlg_strPath->ReleaseBuffer ();
DirDlg_iImageIndex = bInfo.iImage;

if (::SHGetPathFromIDList(pidl,DirDlg_strPath->GetBuffer (MAX_PATH)) == FALSE)
{
pMalloc ->Free (pidl);
pMalloc ->Release ();
return 0;
}

DirDlg_strPath->ReleaseBuffer ();

pMalloc ->Free (pidl);
pMalloc ->Release ();
return 1;
}

void CVMDMakerApp::InitVar()
{
((CMainFrame*)m_pMainWnd)->m_pView=(CVMDMakerView*)((CMainFrame*)m_pMainWnd)->GetActiveView();
ASSERT(((CMainFrame*)m_pMainWnd)->m_pView);
}

调用方法
CString path,title,init;
title="select destination path";
if(1==dirDlg(&path,&title,&init))
{
m_destPath=path;
UpdateData(FALSE);
}
TimiXu 2004-07-02
  • 打赏
  • 举报
回复
楼上
can't compile

看看上面那个,我只需要正确的结果。时间很急。
lixiaosan 2004-07-02
  • 打赏
  • 举报
回复
http://support.microsoft.com/support/kb/articles/Q179/3/78.asp

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧