简体   繁体   English

覆盖CDocument OnFileSave()

[英]Overriding CDocument OnFileSave()

How do I do this? 我该怎么做呢? If you could please kindly include the code for message map and the function itself, that would be greatly appreciated. 如果可以的话,请包含消息映射和功能本身的代码,将不胜感激。

EDIT: 编辑:

More specifically I am wondering how OnFileSave() links to OnSaveDocument(LPCSTR lpszPathName) How does OnFileSave get lpszPathName? 更具体地说,我想知道OnFileSave()如何链接到OnSaveDocument(LPCSTR lpszPathName)OnFileSave如何获得lpszPathName?

You don't need to do anything special to override OnSaveDocument(...) it's already a virtual function in CDocument, so your derived class can just declare virtual BOOL OnSaveDocument(LPCTSTR lpszPathName); 您无需执行任何特殊操作即可覆盖OnSaveDocument(...)因为它已经是CDocument中的虚拟函数,因此您的派生类可以只声明virtual BOOL OnSaveDocument(LPCTSTR lpszPathName); in it's header, then implement it in the document. 在标题中,然后在文档中实现。 Nothing is needed in the message map. 消息映射中不需要任何内容​​。 OnSaveDocument will be called by the framework as part of OnFileSave which is a handler in the base class for ID_FILE_SAVE. 框架将作为OnFileSave的一部分调用OnSaveDocument,后者是ID_FILE_SAVE的基类中的处理程序。 The lpszPathName refers to m_strPathName when called by OnFileSafe, which is set when opening a file or by calling SetPathName. 当由OnFileSafe调用时,lpszPathName引用m_strPathName,该文件是在打开文件或通过调用SetPathName时设置的。 If it's empty when saving, the user is prompted for a file name. 如果在保存时为空,则提示用户输入文件名。

CDocument::OnFileSave is the message handler for the Save menu command. CDocument :: OnFileSave是“保存”菜单命令的消息处理程序。 To handle it yourself put this in your document class message map: 要自己处理,请将其放在文档类消息映射中:

ON_COMMAND(ID_FILE_SAVE, OnFileSave)

and add your function: 并添加您的功能:

void CYOURDOCUMENT::OnFileSave()
{
CDocument::OnFileSave();
}

To see everything it does put a breakpoint in your function and start single-stepping. 要查看一切,它会在您的函数中添加一个断点并开始单步执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM