您的位置:首页 > 编程语言

VS2010/MFC编程入门之十七(对话框:文件对话框)

2013-01-01 17:51 591 查看
http://www.jizhuomi.com/software/173.html


CFileDialog 多选文件

分类: 代码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;

}

}


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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐