1 void CMyDlg::OnBtnBrowsefolder()
2 {
3 // TODO: Add your control notification handler code here
4 BROWSEINFO bInfo;
5 bInfo.hwndOwner = this->m_hWnd; //父窗口句柄
6 bInfo.pidlRoot = NULL; //初始目录
7 bInfo.pszDisplayName = NULL; //
8 bInfo.lpszTitle = "浏览文件夹"; //对话框文本
9 bInfo.ulFlags = 0; //标志
10 bInfo.lpfn = NULL; //回调函数
11 bInfo.lParam = 0; //参数
12 bInfo.iImage = 0; //图像索引
13 ITEMIDLIST* pItemList = SHBrowseForFolder(&bInfo); //弹出对话框
14
15 TCHAR FolderDir[MAX_PATH]; //大小必须指定为MAX_PATH
16 SHGetPathFromIDList(pItemList, FolderDir); //获得路径
17 CString tmp;
18 tmp.Format("%s", FolderDir);
19 MessageBox("文件夹路径为" + tmp, "Tip", MB_ICONINFORMATION);
20 }