Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WM_CLOSE and child windows 2

Status
Not open for further replies.

Zyrenthian

Programmer
Mar 30, 2001
1,440
US
I will most likely write up an app to test this but before I do, has anyone here experimented what happens when a parent window recieves a WM_CLOSE message while it has child windows open? Will the children be notified or not?

Here is why I am asking.

I have written a dll which maintains a list of thread ids or hwnd's along with messages to send to them. The dll does not care what order it calls them in or what the message is. What I want to try and avoid is a situation where I send a WM_CLOSE to a parent window and then send a message to its child.

I am using PostMessage and PostThreadMessage so I dont think it will be a BIG deal if the window or thread does not exist, I will just get a return value of false.

Thanks
Matt

 
Child windows will not be notified due to the WM_CLOSE message itself. But, a normal action when receiving WM_CLOSE would be to call DestroyWindow. And DestroyWindow does destroy all the child windows too.

From the MSDN Library (DestroyWindow):

The DestroyWindow function destroys the specified window. The function sends WM_DESTROY and WM_NCDESTROY messages to the window to deactivate it and remove the keyboard focus from it. The function also destroys the window's menu, flushes the thread message queue, destroys timers, removes clipboard ownership, and breaks the clipboard viewer chain (if the window is at the top of the viewer chain).

If the specified window is a parent or owner window, DestroyWindow automatically destroys the associated child or owned windows when it destroys the parent or owner window. The function first destroys child or owned windows, and then it destroys the parent or owner window.



Marcel
 
BOOL CALLBACK FWnd::FWndClassEx::MDICloseProc(HWND _hWnd, LPARAM lParam)
{
.... with _hWnd
return 1;
}

LERSULT CALLBACK ParentWndProc(HWND _hWnd, int message, WPARAM wParam, LPARAM lParam)
{
....
switch (message)
{
....
case WM_CLOSE:
surpress = true;
WNDENUMPROC fnEnumProc = MDICloseProc;
EnumChildWindows(pMainFrm->m_hClientWnd, fnEnumProc, 0);
FreeProcInstance(fnEnumProc);
break;
}
....
return .....;
}

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Sorry guys, I tried to click the vote button, but it now worky for me :-(

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top