Solved

Cancel Child Window in MDI VS2013 VC++ App

Posted on 2013-11-28
5
499 Views
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.
0
Comment
Question by:rickhill11
  • 3
  • 2
5 Comments
 
LVL 33

Accepted Solution

by:
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).

Sara
0
 
LVL 33

Expert Comment

by:sarabande
ID: 39684825
should be

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

Open in new window

0
 

Author Comment

by:rickhill11
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!
0
 

Author Closing Comment

by:rickhill11
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!
0
 
LVL 33

Expert Comment

by:sarabande
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();

Sara
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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