Cancel Child Window in MDI VS2013 VC++ App

Posted on 2013-11-28
Last Modified: 2013-11-30
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.
Question by:rickhill11
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
  • 3
  • 2
LVL 34

Accepted Solution

sarabande earned 500 total points
ID: 39684824
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).

LVL 34

Expert Comment

ID: 39684825
should be

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

Open in new window


Author Comment

ID: 39685193
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!

Author Closing Comment

ID: 39685197
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!
LVL 34

Expert Comment

ID: 39687650
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();


Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (, we saw how to put the Delete button back there where it belongs.  "Delete" is …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

636 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