文档和串行化
首先利用CArchive结构建立两个读写文档的按钮,读写各种数据;
void CGraphView::OnWrite()
{
CFile file("1.txt",CFile::modeCreate|CFile::modeWrite);
CArchive Archive(&file,CArchive::store);//定义一个archive结构
int i=4;
char ch='a';
float f=1.3f;
CString str("我的测试数据");
Archive<<i<<ch<<f<<str;
}
void CGraphView::OnRead()
{
CFile file("1.txt",CFile::modeRead);
CArchive archive(&file,CArchive::load);
int i;
char ch;
CString str;
CString strResults;
float f;
archive>>i>>ch>>f>>str;
strResults.Format("%d,%c,%2f,%s",i,ch,f,str);
MessageBox(strResults);
}
在Document类里面可以添加函数来来改变自己的窗口:
BOOL CGraphDoc::OnNewDocument()//创建一个新文档,初始化的标题是无标题,可以再此函数里面加载自己的标题
{
if (!CDocument::OnNewDocument())
return FALSE;
//利用CDocument里面的成员函数来设置标题
SetTitle("我的测试窗口");
// (SDI documents will reuse this document)
return TRUE;
}
==================================================================================================================================
CDocTemplate类
CobjectArray 也支持serialize函数,实现文档串行化;
文档串行化真心不太理解,以后加强关注点!