覆盖cdocument C ++ MFC中的onsavedocument [英] Overriding onsavedocument in cdocument C++ MFC

查看:366
本文介绍了覆盖cdocument C ++ MFC中的onsavedocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据CDocument文档:



此函数的默认实现打开指定文件,调用CObject :: Serialize将文档的数据写入该文件,然后将文档标记为干净。如果要在框架保存文档时执行特殊处理,请覆盖此函数。例如,您可以编写一个应用程序,其中文档表示数据库中的记录而不是单独的文件。



这几乎是我覆盖的目的。 OnFileNew在CWinAppEx派生类中很容易绕过,但我无法绕过CDocument类中的File Save。



文档视图使用CListCtrl中填充的数据库中的数据甚至虽然正在调用虚拟OnSaveDocument,但是在打开和关闭另存为对话框后调用它。



我需要绕过保存功能并将消息发送到视图处理。



我绝望地需要这个,希望有人可以提供帮助。



什么我试过了:



在CDocument中覆盖虚函数OnSaveDocument。处理CDocument中的ID_FILE_SAVE和ID_FILE_SAVE_AS(从不调用)。

解决方案

通过在CDocument中覆盖DoSave找到解决方案并返回TRUE将不会提示输入文件名并调用另存为或保存。

According to the CDocument documentation:

The default implementation of this function opens the specified file, calls CObject::Serialize to write the document's data to the file, and then marks the document as clean. Override this function if you want to perform special processing when the framework saves a document. For example, you might write an application where documents represent records in a database rather than separate files.

That is pretty much the purpose I have for overriding. OnFileNew was easy to bypass in the CWinAppEx derived class but I cannot bypass the File Save in the CDocument class.

The documents views use data from databases populated in CListCtrl's and even though the virtual OnSaveDocument is being called it is called AFTER the save as dialog is opened and closed.

I need to bypass the save functionality and send the message to the view for processing.

I need this desperately, I hope someone can help.

What I have tried:

Overriding Virtual function OnSaveDocument in CDocument. Handling ID_FILE_SAVE and ID_FILE_SAVE_AS in CDocument (never called).

解决方案

Found the solution by overriding DoSave in CDocument and returning TRUE will not prompt for file name and call Save As or Save.


这篇关于覆盖cdocument C ++ MFC中的onsavedocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆