Solved

Cancel Child Window in MDI VS2013 VC++ App

Posted on 2013-11-28
5
503 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
[X]
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
5 Comments
 
LVL 34

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 34

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 34

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Mobile 6.5 device Apache Flex 3 50
What is UAC Virtualization in the Process (TASK) Manager? 4 4,793
Need example 5 137
How Do I Widen a Column in a SharePoint 2013 List 2 65
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

739 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