Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to override File Save and File Save As

Posted on 1999-07-29
4
Medium Priority
?
1,846 Views
Last Modified: 2013-11-20
Dear experts

I'm using VC++5.0.
I'd like to override File Save and File Save As which are
called by File menu item.
For this, I installed override function using ID_FILE_SAVE and ID_FILE_SAVE_AS of File menu on CMainFrame.
And in override function, OnFileSave(), I called pDoc->OnFileSave(). But when I select File Save menu item, CMainFrame::OnFileSave() is never called.
How can I call CMainFrame::OnFileSave() and finally pDoc->OnFileSave() when I select File Save ?

Thanks in advance.
0
Comment
Question by:okg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Expert Comment

by:vachooho
ID: 1311890
This may happen if you already have OnFileSave() and OnFileSaveAs() handlers in your view class.

Check all view classes in your project.
Hope you will find where you have message handler for ID_FILE_SAVE

and call OnFileSave() of your CMainFrame within that handler

Note  that some MFC classes has build-in OnfileSave,
actualy CEditView and CRichEditView classes has ID_FILE_SAVE
message handled.


0
 
LVL 31

Expert Comment

by:Zoppo
ID: 1311891
Hi okg,

to vachooho: I think it's not totally correct what you wrote:

The ID_FILE_SAVE(_AS) messages are handled in CDocument's OnFileSave() and OnFileSaveAs(). These functions aren't virtual, so you cannot override them, but they both call virtual function one can override in his CDocument derived class:

void CDocument::OnFileSave() // message handler for ID_FILE_SAVE
{
 DoFileSave();
}

void CDocument::OnFileSaveAs() // message handler for ID_FILE_SAVE_AS
{
 if (!DoSave(NULL))
  TRACE0("Warning: File save-as failed.\n");
}

BOOL CDocument::DoFileSave() // virtual function called by OnFileSave
{
 ...
}

BOOL CDocument::DoSave(LPCTSTR lpszPathName, BOOL bReplace) // virtual function called by OnFileSaveAs
{
 ...
}

So, override DoSave() and DoFileSave() of the document class to change behavior for FileSave(As)

ZOPPO
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 1311892
Hi,

Map the ID_FILE_SAVE and ID_FILE_SAVE_AS menu options to your view class instead of CMainFrame class. The control will come tomthat function first, and then you can do whatever the functionality you want to do in that function in view class.
Hope it helps you.
0
 
LVL 1

Accepted Solution

by:
speedup earned 100 total points
ID: 1311893
first, check your views to see if there's function responding to the file open message. if so, mainframe can't respond to it.

second, check if you've specified the on_afx_msg, and ON_MESSAGE in your codes.

and by the way, why not place your codes in your CYourDoc class to respond to the file open message? if you want to access mainframe, you can get the pointer to it by calling AfxGetMainWnd().
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question