VS2010/MFC编程入门之十七(对话框:文件对话框)
2013-01-01 17:51
591 查看
http://www.jizhuomi.com/software/173.html
分类: 代码2010-06-05
14:39 658人阅读 评论(0) 收藏 举报
[cpp] view
plaincopy
void CxxxDlg::OnBnClickedButtonX()
{
// TODO: Add your control notification handler code here
CString strFileName;
CFileDialog dlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT|OFN_FILEMUSTEXIST,
"图片文件(*.jpg)|*.jpg|文本文件(*.txt)|*.txt|All(*.*)|*.*|", this);
// 自定义用于接收文件名的缓冲区的大小。必须重新分配缓冲区,否则无法同时选择太多的文件。
CONST DWORD nMaxFile = 1024*1024;
char* pbFileNameBuf = new char[nMaxFile];
if ( NULL == pbFileNameBuf )
{
return ; // E_OUTOFMEMORY
}
memset(pbFileNameBuf, 0, nMaxFile);
dlg.m_pOFN->lpstrFile = pbFileNameBuf;
dlg.m_pOFN->nMaxFile = nMaxFile;
if ( IDOK == dlg.DoModal() )
{
POSITION pos = dlg.GetStartPosition();
while ( NULL != pos )
{
strFileName = dlg.GetNextPathName(pos);
//在调试信息区依次输出所选的每一个文件名
OutputDebugString(strFileName);
OutputDebugString("/r/n");
}
}
if ( NULL != pbFileNameBuf )
{
delete[] pbFileNameBuf;
pbFileNameBuf = NULL;
}
}
2010-08-06 09:13:22| 分类: MFC|字号 订阅
// 打开文件
CFileDialog fileDialog = CFileDialog(FALSE, NULL, NULL, OFN_READONLY,
L"GIF Files (*.gif)|*.gif|All Files (*.*)|*.*||",this);
if (fileDialog.DoModal() == IDOK)
{
CString strPath = fileDialog.GetPathName();
}
// 打开文件夹
WCHAR szDir[MAX_PATH];
BROWSEINFO bi;
ITEMIDLIST *pidl;
bi.hwndOwner = this->m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szDir;
bi.lpszTitle = L"请选择目录";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
pidl = SHBrowseForFolder(&bi);
if(pidl == NULL)
return;
if(SHGetPathFromIDList(pidl, szDir))
{
CString m_strSavePath.Format(L"%s", szDir);
}
CFileDialog 多选文件
分类: 代码2010-06-0514:39 658人阅读 评论(0) 收藏 举报
[cpp] view
plaincopy
void CxxxDlg::OnBnClickedButtonX()
{
// TODO: Add your control notification handler code here
CString strFileName;
CFileDialog dlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT|OFN_FILEMUSTEXIST,
"图片文件(*.jpg)|*.jpg|文本文件(*.txt)|*.txt|All(*.*)|*.*|", this);
// 自定义用于接收文件名的缓冲区的大小。必须重新分配缓冲区,否则无法同时选择太多的文件。
CONST DWORD nMaxFile = 1024*1024;
char* pbFileNameBuf = new char[nMaxFile];
if ( NULL == pbFileNameBuf )
{
return ; // E_OUTOFMEMORY
}
memset(pbFileNameBuf, 0, nMaxFile);
dlg.m_pOFN->lpstrFile = pbFileNameBuf;
dlg.m_pOFN->nMaxFile = nMaxFile;
if ( IDOK == dlg.DoModal() )
{
POSITION pos = dlg.GetStartPosition();
while ( NULL != pos )
{
strFileName = dlg.GetNextPathName(pos);
//在调试信息区依次输出所选的每一个文件名
OutputDebugString(strFileName);
OutputDebugString("/r/n");
}
}
if ( NULL != pbFileNameBuf )
{
delete[] pbFileNameBuf;
pbFileNameBuf = NULL;
}
}
CFileDialog打开文件或文件夹操作
2010-08-06 09:13:22| 分类: MFC|字号 订阅// 打开文件
CFileDialog fileDialog = CFileDialog(FALSE, NULL, NULL, OFN_READONLY,
L"GIF Files (*.gif)|*.gif|All Files (*.*)|*.*||",this);
if (fileDialog.DoModal() == IDOK)
{
CString strPath = fileDialog.GetPathName();
}
// 打开文件夹
WCHAR szDir[MAX_PATH];
BROWSEINFO bi;
ITEMIDLIST *pidl;
bi.hwndOwner = this->m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szDir;
bi.lpszTitle = L"请选择目录";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
pidl = SHBrowseForFolder(&bi);
if(pidl == NULL)
return;
if(SHGetPathFromIDList(pidl, szDir))
{
CString m_strSavePath.Format(L"%s", szDir);
}
相关文章推荐
- VS2010/MFC编程入门之十七(对话框:文件对话框)
- (转载)VS2010/MFC编程入门之十七(对话框:文件对话框)
- MFC编程入门之十七(对话框:文件对话框)
- VS2010/MFC编程入门之十七(对话框:文件对话框)
- VS2010/MFC编程入门之十六(对话框:文件对话框)
- VS2010/MFC编程入门之十七(对话框:字体对话框)
- VS2010/MFC编程入门之十七(对话框:字体对话框)
- VS2010/MFC编程入门之六(对话框:创建对话框模板和修改对话框属性)
- VS2010/MFC入门编程五(对话框:模态对话框的弹出过程)
- VS2010/MFC编程入门之三(VS2010应用程序工程中文件的组成结构)
- VS2010/MFC编程入门之三(VS2010应用程序工程中文件的组成结构)
- VS2010/MFC编程入门之五(对话框:创建对话框模板和修改对话框属性)
- (转载)VS2010/MFC编程入门之八(对话框:创建对话框类和添加控件变量)
- VS2010/MFC编程入门之三(VS2010应用程序工程中文件的组成结构)
- VS2010/MFC编程入门之十五(对话框:消息对话框)
- VS2010/MFC编程入门之十五(对话框:一般属性页对话框的创建及显示)
- VS2010/MFC编程入门之四十五(MFC常用类:CFile文件操作类)
- VS2010/MFC编程入门之六(对话框:为对话框添加控件)
- VS2010/MFC编程入门之八(对话框:为控件添加消息处理函数)
- VS2010/MFC编程入门之十一(对话框:非模态对话框的创建及显示)