Solved

Cancel Child Window in MDI VS2013 VC++ App

Posted on 2013-11-28
5
492 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 32

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 32

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 32

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

707 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

14 Experts available now in Live!

Get 1:1 Help Now