http://www.jizhuomi.com/software/173.html
- 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;
- }
- }