设置BROWSEINFO的参数 pidlRoot Address of an ITEMIDLIST structure specifying the location of the root folder from which to browse. Only the specified folder and its subfolders appear in the dialog box. This member can be NULL; in that case, the namespace root (the desktop folder) is used. 用SHBrowseForFolder是很简单,但是无法一次多选目录
char pszBuffer[MAX_PATH];
LPITEMIDLIST pidl;
bi.hwndOwner=GetSafeHwnd();
bi.pidlRoot=NULL;
bi.pszDisplayName=pszBuffer;
bi.lpszTitle=_T("Help");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn=NULL;
bi.lParam=0;
if((pidl=::SHBrowseForFolder(&bi))!=NULL)
{
if(::SHGetPathFromIDList(pidl,pszBuffer))
AfxMessageBox(pszBuffer);
}
我是新手中的新手,看不懂呀
BROWSEINFO是什么?
LPITEMIDLIST是什么?
BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;是什么?
等等。
而BROWSEINFO 只是SHBrowseForFolder的输入参数,是一个结构而已.
其中包括了,调用者句柄,打开目录的根节点,显示在浏览文件夹上的信息等参数,至于他的参数如何设置,可以参考MSDN. 最主要就是要获得,从SHBrowseForFolder 返回的LPITEMIDLIST,即指向ITEMIDLIST 的指针,如果为空,就是按了cancel或者没有选择,如果不为空,则用
SHGetPathFromIDList 获得选中的目录名。
使用API有SHGetDesktopFolder SHGetFileInfo SHGetPathFromIDList等
void CUsageListCtrlDialog::OnButton2()
{
// TODO: Add your control notification handler code here
BROWSEINFO bi;
char pszBuffer[MAX_PATH];
LPITEMIDLIST pidl;
bi.hwndOwner=GetSafeHwnd();
bi.pidlRoot=NULL;
bi.pszDisplayName=pszBuffer;
bi.lpszTitle=_T("Help");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn=NULL;
bi.lParam=0;
if((pidl=::SHBrowseForFolder(&bi))!=NULL)
{
if(::SHGetPathFromIDList(pidl,pszBuffer))
AfxMessageBox(pszBuffer);
}}
#include <shlobj.h>记得这句。
不用生成Dialog 你就当它是通用对话框用吧:)
BROWSEINFO m_pbi ; ::ZeroMemory(&m_pbi, sizeof(BROWSEINFO));
m_pbi.hwndOwner = GetSafeHwnd();
m_pbi.pszDisplayName = buffer;
m_pbi.lpszTitle = "";
m_pbi.ulFlags = BIF_RETURNONLYFSDIRS; ITEMIDLIST *idl = SHBrowseForFolder(&m_pbi);
if (idl)
{
SHGetPathFromIDList (idl, buffer);
}
pidlRoot
Address of an ITEMIDLIST structure specifying the location of the root folder from which to browse. Only the specified folder and its subfolders appear in the dialog box. This member can be NULL; in that case, the namespace root (the desktop folder) is used. 用SHBrowseForFolder是很简单,但是无法一次多选目录
http://www.codeguru.com/vb/articles/2054.shtml
这正是我想要得;
拜托朋友们帮忙想一想
再次谢谢大家。
为了回报大家,我再发一张贴子,请大家来一下
我把三百分(仅有的)全给三个帖子上的朋友,
以示感激!!!
大家继续,请
请
做一个对话框,加入树型控件。用CJ60Lib.dll提供的ShellTree可以做成和windows资源管理器一样的树。
而且使用非常方便,效率很高