怎么让用户选择一个文件夹? 用 CFileDialog 只能选择文件,不能选择文件夹。还有别的方法吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给对话框上放置一个按钮,把它的caption属性设成“...”,然后相应按下按钮的事件:写入下面代码,就可以让用户选择文件夹了: TCHAR szPath[MAX_PATH]; LPITEMIDLIST pitem; BROWSEINFO info; ::ZeroMemory(&info,sizeof(info)); info.hwndOwner=this->m_hWnd; info.lpszTitle=_T("Choose the Folder:"); info.ulFlags=BIF_EDITBOX; if(pitem=::SHBrowseForFolder(&info)) { ::SHGetPathFromIDList(pitem,szPath); UpdateData(FALSE); } m_strPath = szPath;szpath就是得到的目录(文件夹)路径了。 ITEMIDLIST *itemlist = NULL; char szPath[MAX_PATH] = {0}; char szBuffer[MAX_PATH] = {0}; if(this->m_pBrowseSource != NULL) { // return; } this->m_pBrowseSource = new BROWSEINFO(); ZeroMemory(this->m_pBrowseSource,sizeof(BROWSEINFO)); this->m_pBrowseSource->hwndOwner = this->GetSafeHwnd(); this->m_pBrowseSource->pidlRoot = NULL; this->m_pBrowseSource->pszDisplayName = szBuffer; this->m_pBrowseSource->lpszTitle = _T("请选择录音文件的目录:"); this->m_pBrowseSource->ulFlags = BIF_RETURNONLYFSDIRS; this->m_pBrowseSource->lpfn = NULL; this->m_pBrowseSource->lParam = 0; //this->m_pBrowseSource->ulFlags = 0&; itemlist = ::SHBrowseForFolder(this->m_pBrowseSource); SHGetPathFromIDList(itemlist,szPath); if(this->m_pBrowseSource != NULL) { delete this->m_pBrowseSource; this->m_pBrowseSource = NULL; } if(strlen(szPath) > 1) { this->m_DirSource.Format("%s",szPath); this->UpdateData(FALSE); } 在桌面绘图—刷新问题,请教? DeleteFile函数和RemoveDirectory函数执行后,直接把文给干了!怎么不放在回收站呀?搞到我的文件和文件夹不见一大堆。 顶层菜单怎么没有ID值,怎么把他和子层菜单项区别开来呢? 如何将HDC转动角度再显示出来? 问一个令我困惑的问题 如何给菜单项加上Tips? 如何在VC中的DataGrid控件中提取当前记录的字段值? 怎样使程序在任务拦中不可见 关于ListBox的问题。 Enter键的ASCII码是多少? 有谁知道oo4o中open的如下用法: 如何给打印的东西加上网格!HELP!!
TCHAR szPath[MAX_PATH];
LPITEMIDLIST pitem;
BROWSEINFO info;
::ZeroMemory(&info,sizeof(info));
info.hwndOwner=this->m_hWnd;
info.lpszTitle=_T("Choose the Folder:");
info.ulFlags=BIF_EDITBOX; if(pitem=::SHBrowseForFolder(&info))
{
::SHGetPathFromIDList(pitem,szPath);
UpdateData(FALSE);
}
m_strPath = szPath;
szpath就是得到的目录(文件夹)路径了。
char szPath[MAX_PATH] = {0};
char szBuffer[MAX_PATH] = {0}; if(this->m_pBrowseSource != NULL)
{
// return;
} this->m_pBrowseSource = new BROWSEINFO();
ZeroMemory(this->m_pBrowseSource,sizeof(BROWSEINFO));
this->m_pBrowseSource->hwndOwner = this->GetSafeHwnd();
this->m_pBrowseSource->pidlRoot = NULL;
this->m_pBrowseSource->pszDisplayName = szBuffer;
this->m_pBrowseSource->lpszTitle = _T("请选择录音文件的目录:");
this->m_pBrowseSource->ulFlags = BIF_RETURNONLYFSDIRS;
this->m_pBrowseSource->lpfn = NULL;
this->m_pBrowseSource->lParam = 0;
//this->m_pBrowseSource->ulFlags = 0&;
itemlist = ::SHBrowseForFolder(this->m_pBrowseSource);
SHGetPathFromIDList(itemlist,szPath);
if(this->m_pBrowseSource != NULL)
{
delete this->m_pBrowseSource;
this->m_pBrowseSource = NULL;
} if(strlen(szPath) > 1)
{
this->m_DirSource.Format("%s",szPath);
this->UpdateData(FALSE);
}