由于CFileDialog只能选文件,现在只想要目录怎么做?
解决方案 »
- 实习生请教下,要满足公司导入EXCEL到SQL2000的要求,我做了个程序导入简单EXCEL能导入但导入20多个EXCEL列名时出现#idispatch3092
- 各位学数据库的朋友晚上好,请进。
- 一个简单C程序中反三角函数的输出问题
- 如何根据一个矩阵显示出图像
- 一台机器怎么编写基于internet的p2p程序比较好呢?
- 请给一个win2000或XP的debug symbol的详细下载地址
- 关于SetTimer()的问题,谢谢!!
- 我在winxp中用vc调用关机的api ExitWindowsEx(EWX_SHUTDOWN, 0),为什么不好使
- 如何让List Box控件翻动?
- 最最后,英文怎么说?
- select的问题
- 列表控件中的数据绑定之后为什么会被清空 急!
BROWSEINFO bi;
TCHAR szDir[MAX_PATH];
LPITEMIDLIST pidl;
LPMALLOC pMalloc; if (SUCCEEDED(SHGetMalloc(&pMalloc)))
{
ZeroMemory(&bi, sizeof(bi)); bi.hwndOwner = this->m_hWnd;
bi.pszDisplayName = 0;
bi.pidlRoot = 0;
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_VALIDATE ;
pidl = SHBrowseForFolder(&bi);
if (pidl)
{
if (SHGetPathFromIDList(pidl,szDir))
{
m_strDirectory = szDir;
UpdateData(FALSE);
}
pMalloc->Free(pidl);
pMalloc->Release();
}//
else
{
}//end
}
{
CString strResult ="";
LPMALLOC lpMalloc; // pointer to IMalloc
if (::SHGetMalloc(&lpMalloc) != NOERROR)
{
AfxMessageBox("Path operation error!");
return ;
}
char szDisplayName[_MAX_PATH];
char szBuffer[_MAX_PATH];
BROWSEINFO browseInfo;
browseInfo.hwndOwner = this->m_hWnd;
// set root at Desktop
browseInfo.pidlRoot = NULL;
browseInfo.pszDisplayName = szDisplayName;
browseInfo.lpszTitle = "请选择分类数据路径"; // Dialog title
browseInfo.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS;
browseInfo.lpfn = NULL; // not used
browseInfo.lParam = 0; // not used
LPITEMIDLIST lpItemIDList;
if ((lpItemIDList = ::SHBrowseForFolder(&browseInfo))
!= NULL)
{
// Get the path of the selected folder from the item ID list.
if (::SHGetPathFromIDList(lpItemIDList, szBuffer))
{
// At this point, szBuffer contains the path the user chose.
if (szBuffer[0] == '\0')
{
// SHGetPathFromIDList failed, or SHBrowseForFolder failed.
AfxMessageBox("Fail to get directory!",
MB_ICONSTOP|MB_OK);
return ;
}
// We have a path in szBuffer! Return it.
strResult = szBuffer;
}
else
{
// The thing referred to by lpItemIDList
// might not have been a file system object.
// For whatever reason, SHGetPathFromIDList didn't work!
AfxMessageBox("Fail to get directory!",
MB_ICONSTOP|MB_OK);
return ;
}
lpMalloc->Free(lpItemIDList);
lpMalloc->Release();
}
CString strMsg;
strMsg.Format("选择目录:%s",strResult);
AfxMessageBox(strMsg);
UpdateData(FALSE);
}