From: http://blog.sina.com.cn/s/blog_790bb7190100yxm7.html
BROWSEINFO结构如下:
typedef struct _browseinfo
{HWND hwndOwner;LPCITEMIDLIST pidlRoot;LPSTR pszDisplayName;LPCSTR lpszTitle;UINT ulFlags;BFFCALLBACK lpfn;LPARAM lParam;int iImage;
}BROWSEINFO;
调用例子如下:
CString GetfolderPath()
{CString folderPath;BROWSEINFO bi;char buf[MAX_PATH];//初始化入口参数bibi.hwndOwner = NULL;bi.pidlRoot = NULL;bi.pszDisplayName = buf; //此参数如为NULL则不能显示对话框bi.lpszTitle = "选择路径";bi.ulFlags = BIF_RETURNONLYFSDIRS;bi.lpfn = NULL;bi.iImage = 0;LPITEMIDLIST pIDList = SHBrowseForFolder(&bi); //调用显示选择对话框if(pIDList){SHGetPathFromIDList(pIDList,buf); //取得文件夹路径到buf里folderPath = buf; //将路径保存在一个CString对象里}folderPath.Append("\\");return folderPath;
}
===========================================================
使用示例:
void CtzipUncompressDlg::OnBnClickedBtnUncompressto()
{CString folderPath;BROWSEINFO bi;char buf[MAX_PATH] = {0};//初始化入口参数bibi.hwndOwner = NULL;bi.pidlRoot = NULL;bi.pszDisplayName = buf;bi.lpszTitle = "解压缩到...";bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE ;// new Folder buttonbi.lpfn = NULL;bi.iImage = 0;LPITEMIDLIST pIDList = SHBrowseForFolder(&bi); // 显示"浏览文件夹"对话框if(pIDList && SHGetPathFromIDList(pIDList, buf)) // 填充文件夹路径到buf{folderPath = buf;m_sDestDir = folderPath;UpdateData(FALSE);}
}