1、打开一个文件内的内容复制到另一个文件中:
2、打开要复制的文件:
CFileDialog dlg(TRUE,"*","",OFN_ALLOWMULTISELECT,NULL);
if(IDOK==dlg.DoModal())
{
CString str=dlg.GetPathName();
SetDlgItemText(IDC_EDIT1,str);
}
3、实施:
void CCopyFileDlg::OnCopyfile()
{
// TODO: Add your control notification handler code here
CString filename1="";
CString filename2="";
GetDlgItemText(IDC_EDIT1,filename1);
CFileDialog dlg(false,"","",OFN_ALLOWMULTISELECT,NULL);
if(IDOK==dlg.DoModal())
{
filename2=dlg.GetFileName();
CFile file1;
CFile file2;
file1.Open(filename1,CFile::modeReadWrite);
file2.Open(filename2,CFile::modeCreate|CFile::modeReadWrite);
char * c;
c=new char[file1.GetLength()];
file1.Read(c,file1.GetLength());
file2.Write(c,file1.GetLength());
file1.Close();
file2.Close();
//delete c;
AfxMessageBox("文件复制成功");
}
}