MFC——打开文件对话框
来源:互联网 发布:小组抽签软件 编辑:程序博客网 时间:2024/06/02 19:30
在MFC开发中由于操作的文件类型不同,为了方便打开自己需要操作的文件或者满足自己其他的需求常需要重写OnOpenFile()函数,这里根据自己的实际开发记录俩种打开方式,方便自己后期使用,也方便读者学习使用,代码如下:
- 一次打开单个文件
void [类名]::OnFileOpen(){ CString str_temp; str_temp="ObJ文件(*.obj)|*.obj||"; CFileDialog FileDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY, str_temp,NULL); CString filePathName; char *fileName = NULL; if(IDOK == FileDlg.DoModal()) { filePathName = FileDlg.GetPathName(); filePathName.Replace('\\','//'); //将CString转换成char CString str = filePathName.GetBuffer(filePathName.GetLength()); string st = (string)(CStringA)str; int len = st.length(); char* ch = (char*)malloc(len); //动态申请char*大小的空间 for(int i = 0 ; i <len ; i++) { ch[i] = st[i]; } ch[len] = '\0'; //fileName=filePathName.GetBuffer(filePathName.GetLength()); fileName = ch; filePathName.ReleaseBuffer(filePathName.GetLength()); } if (NULL != fileName) { //自己定义的个性操作 }}
- 一次打开多个文件
void [类名]::openMyFile(){ //打开文件对话框 CString str_temp; str_temp="PCD文件(*.pcd)|*.pcd||"; CFileDialog FileDlg(TRUE,NULL,NULL,OFN_ALLOWMULTISELECT | OFN_ENABLESIZING | OFN_HIDEREADONLY, str_temp,NULL);//编辑打开窗口为可选择多个文件 CString filePathName; //存放文件路径,文件全名和文件标题 FileDlg.m_ofn.nMaxFile = 30 * MAX_PATH; //最多可以打开30个文件 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){ //循环读出每个路径并存放在数组中 filePathName = FileDlg.GetNextPathName(pos_file); //文件全路径 string file_Name=(string )(CStringA)filePathName; //将CString类型转换成string类型 // ary_filename.Add(file_Name); Arr_filename.Add(file_Name); } } if (NULL != fileName) { //自己定义的个性操作 }}
阅读全文
0 0
- MFC——打开文件对话框
- MFC打开文件对话框
- MFC 文件打开对话框
- MFC对话框打开文件
- MFC打开文件对话框
- MFC打开文件对话框
- MFC打开文件对话框
- MFC打开文件对话框
- MFC 打开文件对话框
- MFC打开文件对话框
- MFC打开文件对话框
- MFC打开文件对话框
- MFC 打开文件对话框
- MFC打开文件对话框
- MFC打开文件对话框
- MFC打开文件对话框
- MFC打开文件对话框
- MFC打开文件对话框
- Friend Circles
- jdk 安装和eclipse 安装
- Eclipse对html和js代码自动提示
- Shell 流程控制
- angular2 开发 项目生成详解
- MFC——打开文件对话框
- 【线段树 && 区间增减】POJ 3468 A Simple Problem with Integers
- 平衡树(STL)——Luogu2073 送花
- LogService
- C语言实现List的数据结构(很详细的注释)
- 1:计算机语言的发展史
- Spark中RpcEnv和SparkEnv的区别
- 1009. 说反话 (20) Python 2 编译
- Maven 手动添加 JAR 包到本地仓库