?
Solved

Override OnFileNew

Posted on 1997-09-17
6
Medium Priority
?
624 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 800 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
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

752 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