建立一个单文档项目,工具栏上不是有个保存图标,程序如下
void CSeriolView::OnFileSave() //文件保存
{
// TODO: Add your command handler code here
CString strFilePath;
strFilePath = this->GetDocument()->GetPathName();
if ("" == strFilePath)
{
CString m_sNowDataPath = "C:\\";
CString str = m_sNowDataPath + "*.*"; CFileDialog dlg( TRUE,_T("*"), str, //XD: 从对话框中读
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
_T( "All Files|*.*|" "Data Files|*.Dat|") );
if( dlg.DoModal()==IDCANCEL )
{
return ;
}
strFilePath = dlg.GetPathName();
}
//怎么获得文件内容
this->GetDocument()->OnSaveDocument(strFilePath);
this->GetDocument()->SetPathName(strFilePath);
this->GetDocument()->SetTitle(strFilePath);
}
新建个文档,然后输入内容,然后点保存
在保存之前偶要对文件内容进行操作,应该这么做,就是偶要拿到文件的内容!
void CSeriolView::OnFileSave() //文件保存
{
// TODO: Add your command handler code here
CString strFilePath;
strFilePath = this->GetDocument()->GetPathName();
if ("" == strFilePath)
{
CString m_sNowDataPath = "C:\\";
CString str = m_sNowDataPath + "*.*"; CFileDialog dlg( TRUE,_T("*"), str, //XD: 从对话框中读
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
_T( "All Files|*.*|" "Data Files|*.Dat|") );
if( dlg.DoModal()==IDCANCEL )
{
return ;
}
strFilePath = dlg.GetPathName();
}
//怎么获得文件内容
this->GetDocument()->OnSaveDocument(strFilePath);
this->GetDocument()->SetPathName(strFilePath);
this->GetDocument()->SetTitle(strFilePath);
}
新建个文档,然后输入内容,然后点保存
在保存之前偶要对文件内容进行操作,应该这么做,就是偶要拿到文件的内容!
this->GetDocument()->???//把文档内容取出来的函数this->GetDocument()->OnSaveDocument(strFilePath);//这个是保存文件,那文件的内容捏?
偶保存前还要对文件内容排序先
void ReadStringBug()
{
CString strBuffer;
CStdioFile sfMyFile( "C:\\test.txt", CFile::modeRead ); sfMyFile.ReadString( strBuffer );
AfxMessageBox( strBuffer );
sfMyFile.ReadString( strBuffer );
AfxMessageBox( strBuffer );
}
this->GetDocument()->OnSaveDocument(strFilePath);//
this->GetDocument()->SetPathName(strFilePath);
this->GetDocument()->SetTitle(strFilePath);CSeriolDoc* CSeriolView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSeriolDoc)));
return (CSeriolDoc*)m_pDocument;
}
比如我新建个文档,然后编辑,我怎么获得编辑的内容吧,肯定有函数吧?
可能是沟通有问题吧。。大家都不大理解我的意思