void CLXYPolygonTriangulationDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// do something
}
else
{
// do something else.
}
}
打开程序后,第一次通过菜单“打开...”打开一个文档,上面的方法会被调用,之后,再想点击菜单“打开...”来打开一个文档触发上面的Serialize调用时,发现Serialize并没有调用。。
“因为它会先查找一下之前是否已经有打开的该文件,如果找到就返回了。”-引自优快云论坛上某大侠的的一句话。
解决方法:响应ID_FILE_OPEN命令(即菜单的“打开...”命令),响应函数为:
void CLXYPolygonTriangulationDoc::OnFileOpen()
{
CString newName;
if(!theApp.DoPromptFileName(newName,AFX_IDS_OPENFILE,
OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
TRUE,NULL))
return;
POSITION pos=theApp.GetFirstDocTemplatePosition();
CSingleDocTemplate *pDocTemplate=(CSingleDocTemplate *)theApp.GetNextDocTemplate(pos);
pDocTemplate->OpenDocumentFile(newName);
}
这样每次点击菜单“打开...”时,都会触发Serial()调用。
参考:http://bbs.youkuaiyun.com/topics/390781211
This is by design. In a typical MFC application, the Open File command is mapped
to the CWinApp::OnFileOpen() function. In earlier versions of MFC, this function
in turn called the CWinApp::OpenDocumentFile() function. Since MFC 4.0, there is
now an intervening CDocManager class, but the call to OnFileOpen() still