MFC中选择文件夹对话框,选择文件路径

MFC提供的打开文件对话框只能打开文件,如果想选择某个目录的话,就不能使用CFileDialog了,具体实现过程如下:

<textarea cols="50" rows="15" name="code" class="cpp">void COpenFileDlg::OnBnClickedFileOpen2() { //// TODO: 在此添加控件通知处理程序代码 CString m_FileDir; BROWSEINFO bi; ZeroMemory(&amp;bi, sizeof(BROWSEINFO)); bi.hwndOwner = m_hWnd; bi.ulFlags = BIF_RETURNONLYFSDIRS; LPITEMIDLIST pidl = SHBrowseForFolder(&amp;bi); BOOL bRet = FALSE; TCHAR szFolder[MAX_PATH*2]; szFolder[0] = _T('/0'); if (pidl) { if (SHGetPathFromIDList(pidl, szFolder)) bRet = TRUE; IMalloc *pMalloc = NULL; if (SUCCEEDED(SHGetMalloc(&amp;pMalloc)) &amp;&amp; pMalloc) { pMalloc-&gt;Free(pidl); pMalloc-&gt;Release(); } } m_FileDir = szFolder;//选择的文件夹路径 TRACE("/n&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;/n"); TRACE(m_FileDir); TRACE("/n&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;/n"); SaveFilePath = m_FileDir; OnPaint(); } </textarea> 

转自:http://blog.sina.com.cn/s/blog_52f9dd6201009spv.html

你可能感兴趣的:(BI,mfc,Path,2010)