The difference is that
is sent at the start of the window destruction sequence,
WM_NCDESTROY message is sent at the end.
This is an important distinction when you have child windows.
If you have a parent window with a child window,
then the message traffic (in the absence of weirdness)
will go like this:
hwnd = parent, uMsg = WM_DESTROY hwnd = child, uMsg = WM_DESTROY hwnd = child, uMsg = WM_NCDESTROY hwnd = parent, uMsg = WM_NCDESTROY
Notice that the parent receives the
before the child windows are destroyed,
and it receives the
WM_NCDESTROY message after they have
Having two destruction messages, one sent top-down and the other
bottom-up, means that you can perform clean-up appropriate to
a particular model when handling the corresponding message.
If there is something that must be cleaned up top-down, then you can
WM_DESTROY message, for example.
WM_NCDESTROY is the last message your window will
receive (in the absence of weirdness), and it is therefore the best
place to do “final cleanup”.
This is why
our new scratch program
WM_NCDESTROY to destroy its instance
These two destruction messages are paired with the analogous
WM_NCDESTROY is the last message your window receives,
WM_NCCREATE message is the first message,
so that’s a good place to create your instance variables.
Note also that
if you cause the
WM_NCCREATE message to return failure,
then all you will get is
there will be no
WM_DESTROY since you never got the
What’s this “absence of weirdness” I keep alluding to? We’ll look at that next time.
[Typos corrected, 9:30am]