Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 560
  • Last Modified:

Cancel Child Window in MDI VS2013 VC++ App

I have a MDI application that on startup and on FILE->New creates a CDialog.  If the user clicks on CANCEL it creates an empty child.  I would like for

Cancel on the first document, close the whole program.

Cancel on subsequent documents, simply not create a child window.

My CDialog is created in OnInitialUpdate() but can be anyplace that makes sense.

Thanks in advance.
0
rickhill11
Asked:
rickhill11
  • 3
  • 2
1 Solution
 
sarabandeCommented:
an mdi child window (what is a frame window) normally would have a non-modal) formview rather than a modal dialog. The OnInitialUpdate is a CView member function. i assume you have a DoModal call directly in OnInitialUpdate. if so, you would check for the return code of the DoModal. if it is IDCANCEL you could send GetParent().PostMessage(WM_CLOSE, 0, 0); to close the current view, document and frame (mdi child).

Sara
0
 
sarabandeCommented:
should be

GetParent()->PostMessage(WM_CLOSE, 0, 0); 

Open in new window

0
 
rickhill11Author Commented:
Thanks, it worked perfectly.  I was using SendMessage() in essentially the same way, but it kept blowing up.  It never even occurred to me to try PostMessage().

Thanks again!
0
 
rickhill11Author Commented:
Thanks, it worked perfectly.  I was using SendMessage() in essentially the same way, but it kept blowing up.  It never even occurred to me to try PostMessage().

Thanks again!
0
 
sarabandeCommented:
the PostMessage puts the WM_CLOSE at end of message queue. the SendMessage would be handled immediately and would destroy and delete the current window(s) and objects including the one where you called SendMessage.

alternatively to PostMessage call to the frame window you may try to calling GetDocument()->OnCloseDocument();

Sara
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now