user3396028
user3396028

Reputation: 37

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?

Upvotes: 1

Views: 1946

Answers (2)

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10415

CDocument::OnFileSave is the message handler for the Save menu command. 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.

Upvotes: 0

imbtfab
imbtfab

Reputation: 493

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); 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. The lpszPathName refers to m_strPathName when called by OnFileSafe, which is set when opening a file or by calling SetPathName. If it's empty when saving, the user is prompted for a file name.

Upvotes: 1

Related Questions