Solved

Override OnFileNew

Posted on 1997-09-17
6
601 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
[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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 106
ODBC Connection Logging, ADO.NET 6 71
Define unique primary key 9 95
pre4 challenge 19 110
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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 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