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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.