Solved

Override OnFileNew

Posted on 1997-09-17
6
566 Views
Last Modified: 2013-11-19
Hi everyone
I,m working on an MDI app in VC 4.0.
I've made a dialog box which I've connected to a toolbar-button.
I would like the dialog to show everytime I open a new document in my application.
That is, when I push the "new" button I would like the dialog to show and a new empty document to open.
Something like:
void CMyView::OnFileNew()
{
      CWinApp::OnFileNew;
        OnMyButton();
}
The problem is that I'm not allowed to do that because OnFileNew is protected in CWinApp.
What should I do?

The approach above may be completely incorrect. If there is another way to achive what I want I would be more then happy to know.

This cannot be too difficult.

Thanks in advance,

Barney
0
Comment
Question by:barneyman
6 Comments
 
LVL 1

Accepted Solution

by:
kargo earned 200 total points
ID: 1306408
Check out TN022.  This is a tech note that explains the entire process.  In basic; you don't need to overload the function in the base class, you just need to handle the command message.  The technote explains it all.
Ken

0
 

Author Comment

by:barneyman
ID: 1306409
I do not understand the tech note.
0
 
LVL 1

Expert Comment

by:kargo
ID: 1306410
In basic: What you do is use ClassWizard and create a message handler in CWinApp for ID_FILE_NEW.  This will create a function that is called each time File New is hit by the user.  Now you can do whatever you want to do in place of the default handling.  You should look at the source for CWinApp::OnFileNew() and use it as a template since you will propably want to link the calling of new into a document.  I would suggest copying the CWinApp implementation and modifying it to suit your needs.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1306411
Another choice would be to provide a public member function that calls the protected member function in your CWinApp derived class.

For example,

  class CMyWinApp : public CWinApp
  {
  public:
    void NewFile() { CWinApp::OnFileNew(); }
    // other stuff
  };

Then your view can use

  ((CMyWinApp*)theApp)->NewFile();

to create a new document.


0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1306412
Why are you handling file new in a VIEW ????

It SHOULD be handled in an application object, not a view.  In fact, creating a new document from a view does not make much sense, because the view is a view OF A DOCUMENT, so creating a new document will mean the view object will have to kill itself.  It can be done ... but just seems a bit strange.

Also, if you want to get the current application, don't use "theApp", use ::AfxGetApp() instead (this doesn't rely on how you named you app object).

Also again, you cannot call a member function of a non-base class from within a deirved class - ie. you cannot say CWinApp::OnFileNew from within a CView, becaase CView doe NOT derive from CWinApp.  You have to get an object of type CWinApp (from ::AfxGetApp()) and call through that,

0
 

Author Comment

by:barneyman
ID: 1306413
thanks, everyone, yuo're great!!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now