• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 607
  • Last Modified:

Closing a child window in an MDI in OnInitialUpdate()

How do I close out the child window in OnInitialUpdate()?  I tried using GetParent->SendMessage( WM_CLOSE ) and GetParent->SendMessage( WM_DESTROY ),
but they don't work.  WM_CLOSE seems to have no affect on it, and WM_DESTROY causes an exception in the MFC framework.
1 Solution
You need to get the child window and post the WM_CLOSE message.


SendMessage is also OK. But I prefer PostMessage.

WM_DESTROY is a notification message sent by the system.
prokewlAuthor Commented:
GetParent()->PostMessage( WM_CLOSE ) seemed to do the trick, however SendMessage still causes an exception in the MFC FrameWnd class.
Using WM_DESTROY should be done as a signal to your application to perform any final processing necessary before the window is destroyed.  It is the application's way of notifying Windows that it wishes to quit at some time in the future (be it the very near future or some other time relative to the near future).  Consequently, a PostQuitMessage() is usually included as part of the closing out logic since it places a WM_QUIT message in the message queue.

To just use WM_DESTROY may result in your application window getting destroyed, but leaving the application still running (allbeit hidden from view).

The bottom line:  Don't use WM_DESTROY when you what you want is WM_CLOSE.  Use WM_DESTROY when you really and truly mean to terminate, and then don't forget to include the PostQuitMessage function to buy you time to do cleaning up chores.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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