, , ,
/*
:
1. ,
2. ,
3. MFC
*/
// :
void CMyDlg::OnSavebutton()
{
// TODO: Add your control notification handler code here
CFile file;
CString m_path="D:\\test.txt";
if(!file.Open(m_path,CFile::modeRead))
{
MessageBox("Opening file error1!");
return ;
}
int len=file.GetLength();
//
char* buffer=new char[len+1];//
buffer[len]='\0';,
if(!buffer)
{
MessageBox("Allocating fail!");
return;
}
else
{
//
try
{
file.Read(buffer,len);
}
catch(CFileException* e)
{
MessageBox("Reading file error");
file.Close();
e->Delete();
return ;
}
//
buffer[len]='\0';
}
file.Close();
m_path="d:\\total.txt";
if(!file.Open(m_path,CFile::modeWrite|CFile::modeCreate))
{
MessageBox("Opening file error2");
return ;
}
file.SeekToEnd();// ,
file.Write(buffer,len);
file.Close();
delete buffer;
}
// ,
void CMyDlg::OnRead()
{
// TODO: Add your control notification handler code here
CFile file;
if(!file.Open("D:\\test.txt",CFile::modeRead))
{
MessageBox("Opening file error!");
return ;
}
int len=file.GetLength();
char* buffer=new char[len+1];
if(!buffer)
{
MessageBox("Allocating fail");
return ;
}
else
{
try
{
file.Read(buffer,len);
}
catch(CFileException* e)
{
MessageBox("Reading file error");
file.Close();
e->Delete();
return;
}
}
buffer[len]='\0';
m_note=buffer;
delete buffer;
file.Close();
UpdateData(FALSE);
}
void CMyDlg::OnSavepath()
{
// TODO: Add your control notification handler code here
CString msg="File save error";
CFileDialog dlg(true,"TXT",NULL,NULL,"Text file(*.txt)|*.TXT");
//CFileDialog dlg(true,NULL,NULL,NULL,NULL);
if(dlg.DoModal()==IDOK)
{
m_path=dlg.GetPathName();
}
else
{
MessageBox(msg);
}
}