Solved

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

Posted on 2004-04-15
5
260 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
modThree challenge 4 96
Window placement 17 87
MaxSpan challenge 9 105
sumHeights2  challenge 7 114
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

856 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