ArticleDirectory
- Destroywindow Function
- Wm_close message
- Wm_destroy message
- Wm_parentnotify message
- Wm_ncdestroy message
- ActiveX Control destruction
Destroywindow Function
The front function of the destroywindow destruction window.
The msdn description of destroywindows is as follows:
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.
Destroywindow also destroys modeless dialog boxes created by the createdialog function.
A thread cannot use destroywindow to destroy a window created by a different thread.
If the window being destroyed is a child window that does not have the ws_ex_noparentnotify style, a wm_parentnotify message is sent to the parent.
The key points of destroywindow processing are as follows:
1. Send the wm_parentnotify message to the parent window (only when the window has the ws_ex_noparentnotify style );
2. Send the wm_destroy message to the window;
3. Move the window to an inactive state and remove the keyboard focus;
4. Destroy the subwindow (this should be done by calling destroywindow recursively );
5. Destroy target window resources: destroy the menu, clear the message queue of the thread, destroy the timer related to the window process, revoke the window's ownership of the clipboard, and interrupt the view chain of the clipboard;
6. Send the wm_ncdestroy message to the window;
The preceding entries are generally executed from the beginning to the end (the order of 1, 2, and 3 is not certain, and the order of 5 and 6 is not necessarily ). The basis is:
1. According to wm_parentnotify: During window destruction, wm_parentnotify is sent to the parent window before any operation in the window is executed;
2. According to wm_destroy, the message is first sent to the target window and then to all subwindows in the target window. when processing the message, it can be assumed that all subwindows still exist;
3. According to destroywindow Description: The function first destroys the subwindow and its own window, and then destroys the target window;
4. According to wm_ncdestroy: In contrast to wm_destroy, this message is sent after all the sub-windows are destroyed.CodeAccording to the msdn instructions, it is enough.
According to msdn instructions, destroywindow cannot be called on a non-creation thread. to close a window on another thread, you cannot directly call destroywindow (error "Access Denied "), you cannot send wm_destroy only because destroywindow can close the window completely. The wm_destroy message is only part of the closing process, or even the most "useless" part -- wm_destroy is only the interface for user response, the other part of destroywindow is used to clear the window.
To close the window on other threads, you can send a wm_close message to the window. If the window process does not cancel the close operation in the wm_close process, then, defwindowproc calls destroywindow by default (in the creation thread of the window ).
Wm_close message
The msdn description of wm_close is as follows:
An application can prompt the user for confirmation, prior to destroying a window, by processing the wm_close message and calling
Destroywindow function only if the user confirms the choice.
By default, the defwindowproc function callthe destroywindow function to destroy the window.
The wm_close message provides an interface to cancel the window close operation. It can also be used as a unified portal for window close association processing. Clicking the close button in the upper-right corner of the window will cause the window to receive the wm_close message. Generally, the exit Item Processing code in the menu should also send the wm_close message to the window, in this way, no matter which method the window is triggeredProgramThe flow will flow into the processing process of the wm_close message. In wm_close, you can confirm the program status, automatically or by the user to confirm whether to cancel the close operation.
Compared with other messages, wm_close occurs before the destruction process starts. After the user finishes processing the wm_close message, if it is not canceled, defwindowproc will call destroywindow to close the window. Once the window enters destroywindow, the closing process will be irreversible.
Wm_destroy message
The msdn description of wm_destroy is as follows:
The wm_destroy message is sent when a window is being destroyed. It is sent to the window procedure of the window being destroyed after the window is removed from the screen.
This message is sent first to the window being destroyed and then to the child windows (if any) as they are destroyed. during the processing of the message, it can be assumed that all child windows still exist.
A window functions es this message through its windowproc function.
If the window being destroyed is part of the clipboard viewer chain (set by calling the setclipboardviewer function ), the window must remove itself from the chain by processing the changeconboardchain function before returning from the wm_destroy message.
The last sentence is worth noting, but I am not very familiar with the clipboard.
Wm_parentnotify message
The msdn description of wm_parentnotify is as follows:
The wm_parentnotify message is sent to the parent of a child window when the child window is created or destroyed, or when the user clicks a mouse button while the cursor is over the child window. when the child window is being created, the system sends wm_parentpolicy just before the createwindow or create1_wex function that creates the window returns. when the child window is being destroyed, the system sends the message before any processing to destroy the window takes place.
A window functions es this message through its windowproc function.
Wm_ncdestroy message
The msdn description of wm_ncdestroy is as follows:
The wm_ncdestroy message informs a window that its nonclient area is being destroyed. the destroywindow function sends the wm_ncdestroy message to the window following the wm_destroy message. wm_destroy is used to free the allocated memory object associated with the window. the wm_ncdestroy message is sent after the child windows have been destroyed. in contrast, wm_destroy is sent before the child windows are destroyed. A window functions es this message through its windowproc function. this message frees any memory internally allocated for the window.
As for wm_destroy and wm_ncdestroy, we can see from various descriptions that a notification interface is used to close the operation at startup, and a notification interface is used to close the operation at completion. This is also why I think that in the destroywindow processing process, 6th are after 5th.
In addition, it is worth mentioning that wm_destroy is used to release allocated memory objects in the associated to window, wm_ncdestroy is used to release the internal memory allocated for the window (internally allocated. As you can imagine, the latter should refer to the kernel data of the window, but the former has various possibilities: menu resources? GDI resources? Exclusive or subwindow resource? This is hard to say. Moreover, according to the two statements, it seems that these two cleanup operations occur during message processing. However, they are obviously not the work done by users, this should be done in defwindowproc. Why don't we get the destroywindow and execute it?
ActiveX Control destruction
The best way to destroy a control is to destroy the host window. You can explicitly destroy the host window by calling cwindow: destroywindow or destroywindow API, or destroy the parent window of the host window to cause it to die, thereby implicitly destroying the host window. Any of these methods will safely destroy the hosted controls. Please note that the destruction of the caxwindow object will not "cause the destruction of the basic" atlaxwin7 "window.
From: http://technet.microsoft.com/zh-cn/query/cc468138