Solved

Conditionally allow creation of new Child Frames in an MDI application using MFC

Posted on 2004-04-15
5
237 Views
Last Modified: 2013-11-20
Hello,

I have written an MDI application using Visual C++ and MFC 6 with Doc/View support. The UI is like this: MDI App with each Child Frame divided into 2 Views with a SplitterWnd, first one a CEditView derived class where the user can enter any Sql query. Second, a CView derived class where the results of the query are displayed in a child Grid control which resizes fully to cover the parent view. This is what I want to accomplish:

When the user chooses File->New (CWinApp::OnFileNew()), I want to present a modal dialog with UserName,Password and a list of valid Dsn's. If the connection is succussfully, allow the framework to create the new child frame with the 2 Views, if he clicks cancel, the new child frame with the 2 views should not be created. I have created the dialog and tested it, no issues there.

I want to know where to put code so that the I can stop the MFC architechture from creating the new child frame when the validation fails. Please help me out in this regard.

Thanks,

Balaji
0
Comment
Question by:BalajiS
  • 2
5 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
ID: 10831016
In MDI application created by MFC Application Wizard there is the following line:

ON_COMMAND(ID_FILE_NEW, OnFileNew)

in the application class message map. You need to provide your own message handler:

afx_msg void OnMyFileNew( );      // in h-file


ON_COMMAND(ID_FILE_NEW, OnMyFileNew)        // in message map, instead of ON_COMMAND(ID_FILE_NEW, OnFileNew)


Implementation:

void CMyApp::OnMyFileNew()
{
    // Show dialog here
    // If succeeded, call CWinApp::OnFileNew();
    // which actually creates new frame
}




0
 

Author Comment

by:BalajiS
ID: 10841154
Thanks a lot for your valuable suggestion. I did the same for OnFileOpen and it works fine.

The only issue remaining is that how do I tackle MRU menu items. I understand MFC uses a pre-wired handler for ID_FILE_MRU_1 and opens the document dyanmically from the selection. Can I handle this too ?

Balaji
0
 

Author Comment

by:BalajiS
ID: 11124126
That's ok, you can close the question. I have been able to solve it completely.

Thanks,

Balaji
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

12 Experts available now in Live!

Get 1:1 Help Now