“Combo Box”,“List Box”以及"Check Box"的使用,对于一些常见的问题解决方法在这里做一个小小的总结。 OFN_ALLOWMULTISELECT | OFN_ENABLESIZING | OFN_HIDEREADONLY,filters); //获取第一个文件的位置 POSITION pos_file; pos_file = fileDlg.GetStartPosition(); //读出每个路径并存放在数组中 while(pos_file != NULL) { //将文件路径增加至字符串末尾,以空格分隔,在这里也可以定义一个数组存放 fileName = fileDlg.GetNextPathName(pos_file); fileName += " "; m_filename.Add(fileName); } fileName=fileName.Left(fileName.GetLength()-1);//去掉最后一个空格 _T("Describe Files (*.zv)|*.zv|All Files (*.*)|*.*||"), NULL); if (dlgFile.DoModal()) { fileName = dlgFile.GetPathName(); //存放选择的目录路径 ZeroMemory(szPath, sizeof(szPath)); bi.hwndOwner = m_hWnd; bi.pidlRoot = NULL; bi.pszDisplayName = szPath; bi.lpszTitle = "请选择文件目录:"; bi.lpfn = NULL; bi.lParam = 0; bi.iImage = 0; //弹出选择目录对话框 LPITEMIDLIST lp = SHBrowseForFolder(&bi); //转换成CString格式的字符串 CatalogName.Format("%s",szPath); FILE * newfile, * oldfile; //定义“新”,“老”文件 CString filter = "(*..txt)|*..txt||"; //文件过虑的类型 if(openFileDlg.DoModal() == IDOK) //获取用户填写的新文件名 CString check = openFileDlg.GetPathName(); //以“写”方式打开 newfile = fopen(check,"wb"); if( newfile == NULL) { AfxMessageBox("新文件创建失败"); } //自己定义了一个文件列表,读取到每一个文件,依次写入 for (int i = 0;i<count;i++) { //文件名称临时变量 CString oldfilenametemp; //获取文件名 m_myfilelist->GetText(i,oldfilenametemp); //以“读”的方式打开 oldfile = fopen(oldfilenametemp,"rb"); //定义char型数组存放数据,MAXLEN是我自己定义的宏,长度为512*1024 unsigned char buf[MAXLEN]; //存放结果,如果读取文件成功,返回真正读取到的字节数 int rc; //只要文件没有结束,一直读 while( (rc = fread(buf,sizeof(unsigned char), MAXLEN,oldfile)) != 0 ) { //将读取的内容写到新文件的末尾 fwrite( buf, sizeof( unsigned char ), rc, newfile ); } } //关闭文件 fclose(oldfile); fclose(newfile); AfxMessageBox("合并成功"); AfxMessageBox("文件打开失败"); newfilelen = size*1048576; FILE * newfile;//定义新文件 //以“写”方式打开指定“path”路径的文件(其实就是新文件的保存路径) newfile = fopen(path,"wb"); //定义拆分文件长度的char型缓冲区 unsigned char * buf = new unsigned char[newfilelen]; //读取结果 int rc; //从旧文件读出固定长度,存放到buf oldfile = fopen(oldfilepath,"rb"); //设置偏移量 long offset = i * newfilelen; //进行偏移 fseek(oldfile,offset,SEEK_SET); rc = fread(buf,sizeof(unsigned char),newfilelen,oldfile); //写入新文件中 fwrite( buf, sizeof( unsigned char ), rc, newfile ); //关闭新文件 fclose(newfile);