如何选定一个文件夹(而不是文件)以便CFileFind找文件?马上结 谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://community.csdn.net/Expert/topic/3784/3784163.xml?temp=.7860376 LPITEMIDLIST pidl; LPITEMIDLIST pidlRoot; LPMALLOC lpMalloc; TCHAR pszPath[MAX_PATH]; _tcscpy(pszPath, ""); BROWSEINFO bi = { m_hWnd, NULL, (char *)(LPCTSTR)pszPath, "请选择存放的路径:", BIF_BROWSEFORCOMPUTER | BIF_RETURNONLYFSDIRS, NULL, 0L, 0}; if (0 != SHGetSpecialFolderLocation(HWND_DESKTOP, CSIDL_DRIVES, &pidlRoot)) { return; } if (NULL == pidlRoot) { return; } bi.pidlRoot = pidlRoot; pidl = SHBrowseForFolder(&bi); if (NULL != pidl) { SHGetPathFromIDList(pidl, pszPath); m_strFilePath = pszPath; } else { return; } // Get the shell's allocator to free PIDLs if (!SHGetMalloc(&lpMalloc) && (NULL != lpMalloc)) { if (NULL != pidlRoot) { lpMalloc->Free(pidlRoot); } if (NULL != pidl) { lpMalloc->Free(pidl); } lpMalloc->Release(); } void CSelFileDlg::OnAdddir() { // TODO: Add your control notification handler code here LPMALLOC pMalloc; BROWSEINFO bi; LPITEMIDLIST pidl; TCHAR m_directory[MAX_PATH]; ::ZeroMemory(&bi, sizeof(bi)); // Gets the Shell's default allocator if (::SHGetMalloc(&pMalloc) == NOERROR) { // Get help on BROWSEINFO struct - it's got all the bit settings. bi.hwndOwner=NULL; bi.pidlRoot=NULL;//为NULL,则已桌面为根, bi.lpszTitle=_T("请选择文件夹");// bi.ulFlags=BIF_RETURNONLYFSDIRS; bi.lpfn=NULL; bi.lParam=NULL; bi.pszDisplayName = m_directory; // This next call issues the dialog box. if ((pidl = ::SHBrowseForFolder(&bi)) != NULL) { if (!::SHGetPathFromIDList(pidl, m_directory)) pMalloc->Free(pidl); //m_directory 就保存了你选择的文件夹 } pMalloc->Release(); } // m_bdirectory = true;} CString sFolder; //存放选定一个文件夹 LPMALLOC pMalloc; // Gets the Shell's default allocator if (::SHGetMalloc(&pMalloc) == NOERROR) { BROWSEINFO bi; char pszBuffer[MAX_PATH]; LPITEMIDLIST pidl; bi.hwndOwner = GetSafeHwnd(); bi.pidlRoot = NULL; bi.pszDisplayName = pszBuffer; bi.lpszTitle = _T("Select a directory..."); bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS; bi.lpfn = NULL; bi.lParam = 0; // This next call issues the dialog box. if ((pidl = ::SHBrowseForFolder(&bi)) != NULL) { if (::SHGetPathFromIDList(pidl, pszBuffer)) { // At this point pszBuffer contains the selected path sFolder = pszBuffer; } // Free the PIDL allocated by SHBrowseForFolder. pMalloc->Free(pidl); } // Release the shell's allocator. pMalloc->Release(); } 没有一种如“OPENFILENAME”好用的东西吗? 请教各位大侠一个控制台的小问题!!!! 购买基于VRML面向WEB应用的数控加工程序仿真系统模块的集成系统 什么是屏幕坐标,什么是设备坐标? 大家帮我看看,我的线程哪里有毛病 请高手提供关于中间件设计技术方面的入门书籍?(Up有分) 怎样利用成千上万的现成的winamp skin? 请问谁知道ATX电源关机的汇编指令 VC调试问题 指针读内存问题 怎么判断CEvent是在事件信号状态还是空闲状态 麻烦高手看看 公司老板想要搞一套在家里可以查看公司车间运行状况的系统。
LPITEMIDLIST pidlRoot;
LPMALLOC lpMalloc; TCHAR pszPath[MAX_PATH];
_tcscpy(pszPath, ""); BROWSEINFO bi = { m_hWnd, NULL, (char *)(LPCTSTR)pszPath, "请选择存放的路径:", BIF_BROWSEFORCOMPUTER | BIF_RETURNONLYFSDIRS, NULL, 0L, 0};
if (0 != SHGetSpecialFolderLocation(HWND_DESKTOP, CSIDL_DRIVES, &pidlRoot))
{
return;
} if (NULL == pidlRoot)
{
return;
} bi.pidlRoot = pidlRoot; pidl = SHBrowseForFolder(&bi);
if (NULL != pidl)
{
SHGetPathFromIDList(pidl, pszPath); m_strFilePath = pszPath;
}
else
{
return;
}
// Get the shell's allocator to free PIDLs
if (!SHGetMalloc(&lpMalloc) && (NULL != lpMalloc))
{
if (NULL != pidlRoot)
{
lpMalloc->Free(pidlRoot);
}
if (NULL != pidl)
{
lpMalloc->Free(pidl);
}
lpMalloc->Release();
}
void CSelFileDlg::OnAdddir()
{
// TODO: Add your control notification handler code here
LPMALLOC pMalloc;
BROWSEINFO bi;
LPITEMIDLIST pidl;
TCHAR m_directory[MAX_PATH];
::ZeroMemory(&bi, sizeof(bi));
// Gets the Shell's default allocator
if (::SHGetMalloc(&pMalloc) == NOERROR)
{
// Get help on BROWSEINFO struct - it's got all the bit settings.
bi.hwndOwner=NULL;
bi.pidlRoot=NULL;//为NULL,则已桌面为根,
bi.lpszTitle=_T("请选择文件夹");//
bi.ulFlags=BIF_RETURNONLYFSDIRS;
bi.lpfn=NULL;
bi.lParam=NULL;
bi.pszDisplayName = m_directory;
// This next call issues the dialog box.
if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)
{
if (!::SHGetPathFromIDList(pidl, m_directory))
pMalloc->Free(pidl);
//m_directory 就保存了你选择的文件夹
}
pMalloc->Release();
} //
m_bdirectory = true;
}
LPMALLOC pMalloc; // Gets the Shell's default allocator
if (::SHGetMalloc(&pMalloc) == NOERROR)
{
BROWSEINFO bi;
char pszBuffer[MAX_PATH];
LPITEMIDLIST pidl; bi.hwndOwner = GetSafeHwnd();
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("Select a directory...");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0; // This next call issues the dialog box.
if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)
{
if (::SHGetPathFromIDList(pidl, pszBuffer))
{
// At this point pszBuffer contains the selected path
sFolder = pszBuffer;
} // Free the PIDL allocated by SHBrowseForFolder.
pMalloc->Free(pidl);
}
// Release the shell's allocator.
pMalloc->Release();
}