Reference 1: http://blog.csdn.net/oldmtn/article/details/6904697
Reference 2: http://bbs.csdn.net/topics/390405810
The C ++ class in VC encapsulates the window handle.
C ++ usually deletes the dynamically allocated memory in the destructor.
Window A deletes all its subwindows in ondestroy.
We cannot delete the subwindow here for a while, and delete the memory allocated by the C ++ class for a while, which is too messy and difficult to maintain and understand.
Because the C ++ class and window handle are bound together, it cannot be said that the window has been destory, but the memory allocated by the C ++ member variables still exists;
It cannot be said that the memory allocated by the member variables is still present, but the window handle does not exist. These two possibilities are meaningless.
Therefore, we need a unified method to ensure that the window is destroy, and the window member variable does not exist...
Therefore, we need the following definition:
Assume that a ctestwnd is derived from cwnd and serves as a subwindow of other windows.
In general, when we encapsulate the ctestwnd, we 'd better reload its postncdestroy function. Here we call delete this. After the window is deleted, delete is used to trigger the destructor,
Delete the C ++ object.
Here is the window class we encapsulate.
However, for the parent window of ctestwnd, we only need to call the destroywindow function of each subwindow (ctestwnd) in sequence in its: ondestroy ..