With child windows the parent first receives WM_DESTROY
then the child windows. With owned windows it's the opposite. The owned windows first receive WM_DESTROY
then the owner. If I want to modify something that will affect the child windows, I can do it in WM_DESTROY
of parent window, but I can't do the same with owned windows. Owned windows will receive WM_DESTROY
before the owner does.
Asked
Active
Viewed 336 times
1

Mike32ab
- 466
- 1
- 3
- 13
-
1[What is the difference between WM_DESTROY and WM_NCDESTROY?](https://blogs.msdn.microsoft.com/oldnewthing/20050726-00/?p=34803) – IInspectable Jul 18 '16 at 19:13
1 Answers
0
The official documentation for DestroyWindow()
says otherwise:
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.
Are you sending WM_DESTROY
by hand instead of calling DestroyWindow()
?

Ben Voigt
- 277,958
- 43
- 419
- 720
-
I'm not sending `WM_DESTROY`. I wrote a test program and for child windows it's the opposite of what the documentation says. Child windows receive `WM_DESTROY` after parent does – Mike32ab Jul 18 '16 at 19:02
-
@Rm32a: Ahh, [this other answer](http://stackoverflow.com/a/3155879/103167) contains the key: `WM_NCDESTROY` is sent in actual order of destruction, `WM_DESTROY` is sent early, before the check for and destruction of child windows. – Ben Voigt Jul 18 '16 at 19:06
-
The answer given seems to be the right answer to your question. If you send WM_DESTROY to a window (either via SendMessage, PostMessage or DestroyWindow), the OS will thereafter send WM_DESTROY and WM_NCDESTROY to its children, How else would the OS know that child windows need get this message if it wasn't first sent to the parent? Perhaps I misunderstand your question. – clarasoft-it Jul 18 '16 at 19:09
-
2@clarasoft-it: No, **you** don't send `WM_DESTROY` to a window. `DestroyWindow` sends `WM_DESTROY` and `WM_NCDESTROY` and actually performs the destruction. See https://blogs.msdn.microsoft.com/oldnewthing/20110926-00 – Ben Voigt Jul 18 '16 at 19:11
-