CString pathName = _T("");
CString fileName = _T("");
CString strMulfilepath = _T("");
//创建一个可以选择多个文件的CFileDialog
CFileDialog fileDlg(true,NULL,_T("*.*"),OFN_ALLOWMULTISELECT | OFN_ENABLESIZING | OFN_HIDEREADONLY,_T("All Files (*.*)|*.*||"));
m_filepath.clear();
//最多可以打开500个文件
fileDlg.m_ofn.nMaxFile = 500 * MAX_PATH;
TCHAR* ch = new TCHAR[fileDlg.m_ofn.nMaxFile];
fileDlg.m_ofn.lpstrFile = ch;
//对内存块清零
ZeroMemory(fileDlg.m_ofn.lpstrFile,sizeof(TCHAR) * fileDlg.m_ofn.nMaxFile);
//显示文件对话框,获得文件名集合
if(fileDlg.DoModal() == IDOK){
//获取第一个文件的位置
POSITION pos_file;
pos_file = fileDlg.GetStartPosition();
//循环读出每个路径并存放在数组中
while(pos_file != NULL){
//将文件路径存放在数组中
pathName = fileDlg.GetNextPathName(pos_file);
int len =WideCharToMultiByte(CP_ACP,0,pathName,-1,NULL,0,NULL,NULL);
char *cfname =new char[len +1];
WideCharToMultiByte(CP_ACP,0,pathName,-1,cfname,len,NULL,NULL );
//ary_filename.Add(pathName);
m_filepath.push_back(cfname);
strMulfilepath += pathName;
}
}
SetDlgItemText(IDC_EDIT1, strMulfilepath);
delete[] ch;