MFC CDocument子类中的Serialize(CArchive& ar)方法,在打开文档时调用一次之后,再点击“打开”菜不被调用,解决。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值