用CFileDialog对话框时,怎么样来打开文件夹 在CFileDialog中,打开时必须是打开一个具体的文件,才能确定,怎么样来选定一个文件夹,就可以确定,然后退出对话框。谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if(FileDlg.DoModal() == IDOK) { m_valFileName = FileDlg.GetPathName(); POSITION Pos; Pos = FileDlg.GetStartPosition(); while(Pos) { m_valFileName = FileDlg.GetNextPathName(Pos); if(m_valFileName != _T("")) { if(m_ctrFileName.FindString(-1, m_valFileName) >= 0) { MessageBox("文件\"" + m_valFileName+"\"已经存在", "错误提示", MB_OK|MB_ICONWARNING); continue; } else { m_ctrFileName.AddString(m_valFileName); } } // end of if(m_valFileName != _T("")) } // end of while(Pos) } // end of if(FileDlg.DoModal() == IDOK) 用:SHBrowseForFolder如:BROWSEINFO stBrowseInfo;ITEMIDLIST *pstItemIdList; TCHAR acFilePath[_MAX_PATH]; // open select directory dialogmemset(&stBrowseInfo, 0, sizeof(BROWSEINFO));stBrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS; pstItemIdList = SHBrowseForFolder(&stBrowseInfo);SHGetPathFromIDList(pstItemIdList, acFilePath); 我自己前些天也写了一个打开文件夹的小程序,我觉得要打开文件夹不应用CFiledialog函数吧.以下是手写的一段类,可参考....class CDirDialog{public: CDirDialog(); virtual ~CDirDialog(); BOOL DoModal(CWnd *pwndParent = NULL); void SetWindowTitle(CString title){m_strWindowTitle = title;} void SetTitle(CString title){m_strTitle = title;} void SetSelDir(CString Dir){m_strSelDir = Dir;} void SetRootDir(CString Dir){m_strInitDir = Dir;} CString GetWindowText(){return m_strWindowTitle;} CString GetTitle(){return m_strTitle;} CString GetPathname(){return m_strPath;}protected: CString m_strWindowTitle; CString m_strPath; CString m_strInitDir; CString m_strSelDir; CString m_strTitle; int m_iImageIndex; BOOL m_bStatus;private: virtual BOOL SelChanged(LPCSTR lpcsSelection, CString& csStatusText) { return TRUE; }; static int __stdcall CDirDialog::BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData);}; MFC图片资源载入的问题! activex控件,如何在隐藏状态下接收事件 VC++6.0中如何高速处理窗口中的数据包 怎样制作word中的字号列表 一个作品欣赏 MFC中如何实现多个数据的输入输出 Mp3的VBR格式是怎么回事啊,有知道的说两句。 急求解答!如何在vc程序里调用word后在对word菜单就行控制?希望各位仁兄多指教! 一个基本的拨号程序问题 CxImage在读取分辨率高的图片时,LOAD失败,高分处理,在线等待。 请问C++同VC有什么区别。 请教 : VC对数据库编程 如何在对话框的编辑框里显示从数据库里查询到的某一数据
{
m_valFileName = FileDlg.GetPathName();
POSITION Pos;
Pos = FileDlg.GetStartPosition(); while(Pos)
{
m_valFileName = FileDlg.GetNextPathName(Pos); if(m_valFileName != _T(""))
{
if(m_ctrFileName.FindString(-1, m_valFileName) >= 0)
{
MessageBox("文件\"" + m_valFileName+"\"已经存在",
"错误提示", MB_OK|MB_ICONWARNING);
continue;
}
else
{
m_ctrFileName.AddString(m_valFileName); }
} // end of if(m_valFileName != _T(""))
} // end of while(Pos)
} // end of if(FileDlg.DoModal() == IDOK)
BROWSEINFO stBrowseInfo;
ITEMIDLIST *pstItemIdList;
TCHAR acFilePath[_MAX_PATH]; // open select directory dialog
memset(&stBrowseInfo, 0, sizeof(BROWSEINFO));
stBrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS; pstItemIdList = SHBrowseForFolder(&stBrowseInfo);
SHGetPathFromIDList(pstItemIdList, acFilePath);
{
public: CDirDialog();
virtual ~CDirDialog(); BOOL DoModal(CWnd *pwndParent = NULL); void SetWindowTitle(CString title){m_strWindowTitle = title;}
void SetTitle(CString title){m_strTitle = title;}
void SetSelDir(CString Dir){m_strSelDir = Dir;}
void SetRootDir(CString Dir){m_strInitDir = Dir;} CString GetWindowText(){return m_strWindowTitle;}
CString GetTitle(){return m_strTitle;}
CString GetPathname(){return m_strPath;}protected:
CString m_strWindowTitle;
CString m_strPath;
CString m_strInitDir;
CString m_strSelDir;
CString m_strTitle;
int m_iImageIndex;
BOOL m_bStatus;private: virtual BOOL SelChanged(LPCSTR lpcsSelection, CString& csStatusText) { return TRUE; };
static int __stdcall CDirDialog::BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData);
};