• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天下

            記錄修行的印記

            窗口銷毀的相關(guān)函數(shù)與消息

            窗口銷毀的相關(guān)函數(shù)與消息
            DestroyWindow函數(shù)
            DestroyWindow銷毀窗口的正牌函數(shù)。
            DestroyWindows的MSDN說明如下:
            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.
            DestroyWindow的處理過程總結(jié)要點如下: 
            1. 向父窗口發(fā)送WM_PARENTNOTIFY消息(僅當(dāng)窗口具有WS_EX_NOPARENTNOTIFY樣式); 
            2. 向窗口發(fā)送WM_DESTROY消息; 
            3. 使窗口轉(zhuǎn)入非活動狀態(tài),移除鍵盤焦點; 
            4. 銷毀子窗口(應(yīng)該是通過遞歸調(diào)用DestroyWindow完成); 
            5. 銷毀目標(biāo)窗口資源:銷毀菜單,清空線程的消息隊列,銷毀與窗口過程相關(guān)的定時器,解除窗口對剪貼板的擁有權(quán),打斷剪貼板器的查看鏈; 
            6. 向窗口發(fā)送WM_NCDESTROY消息;
            上述條目大致從前往后執(zhí)行(1、2、3的順序不一定,5、6的順序不一定)。依據(jù)是: 
            1. 根據(jù)WM_PARENTNOTIFY說明:銷毀窗口時,系統(tǒng)在任何銷毀窗口的操作執(zhí)行前發(fā)送WM_PARENTNOTIFY至父窗口; 
            2. 根據(jù)WM_DESTROY說明:此消息先被發(fā)送至目標(biāo)窗口,然后發(fā)送給目標(biāo)窗口的所有子窗口,處理此消息時,可以假定所有子窗口還存在著; 
            3. 根據(jù)DestroyWindow說明:函數(shù)先銷毀子窗口及所擁有的窗口,然后銷毀目標(biāo)窗口; 
            4. 根據(jù)WM_NCDESTROY說明:與WM_DESTROY相反的是,此消息在所有子窗口銷毀之后發(fā)送; 沒有去看匯編代碼,只是根據(jù)各個MSDN說明來大致推測的,基本夠用了吧。
            根據(jù)MSDN說明,不能在非創(chuàng)建線程上調(diào)用DestroyWindow;若要在其它線程上關(guān)閉窗口,不可以直接調(diào)用DestroyWindow(錯誤"拒絕訪問"),也不可以只發(fā)送WM_DESTROY,因為DestroyWindow才能完整的關(guān)閉窗口,WM_DESTROY消息只是關(guān)閉流程的一部分,甚至是最"無用"的一部分--WM_DESTROY只是用戶響應(yīng)的接口,而真正清理窗口的工作由DestroyWindow的其它部分完成。 
            要在其它線程上關(guān)閉窗口,可以向窗口發(fā)送WM_CLOSE消息,若窗口過程未在WM_CLOSE的處理中取消關(guān)閉操作,則DefWindowProc會默認調(diào)用DestroyWindow(彼時自然是在窗口的創(chuàng)建線程上)。
            WM_CLOSE消息
            WM_CLOSE的MSDN說明如下:
            An application can prompt the user for confirmation, prior to destroying a window, by processing the WM_CLOSE message and calling the 
            DestroyWindow function only if the user confirms the choice.
            By default, the DefWindowProc function calls the DestroyWindow function to destroy the window.
            WM_CLOSE消息提供取消關(guān)閉窗口操作的接口,也可以作為窗口關(guān)閉的關(guān)聯(lián)處理的統(tǒng)一入口。點擊窗口右上角的關(guān)閉按鈕將導(dǎo)致窗口收到WM_CLOSE消息,一般情況下,菜單中的Exit項的處理代碼中也應(yīng)向窗口發(fā)送WM_CLOSE消息,這樣可以使無論何種方式觸發(fā)的窗口關(guān)閉操作,其程序流均會流入WM_CLOSE消息的處理過程。在WM_CLOSE中可以對程序狀態(tài)進行確認,自動或由用戶確認是否取消關(guān)閉操作。 
            與接下來的其它消息相比,WM_CLOSE的特殊之處在于它發(fā)生在銷毀過程啟動之前。用戶處理完WM_CLOSE消息后,如未取消,則DefWindowProc將調(diào)用DestroyWindow來關(guān)閉窗口,一旦進入DestroyWindow,則關(guān)閉過程將不可逆轉(zhuǎn)。
            WM_DESTROY消息
            WM_DESTROY的MSDN說明如下:
            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 receives 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 ChangeClipboardChain function before returning from the WM_DESTROY message.
            最后一句值得注意,不過對剪貼板涉獵不多,暫且不究。
            WM_PARENTNOTIFY消息
            WM_PARENTNOTIFY的MSDN說明如下:
            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_PARENTNOTIFY just before the CreateWindow or CreateWindowEx 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 receives this message through its WindowProc function.
            WM_NCDESTROY消息
            WM_NCDESTROY的MSDN說明如下:
            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 receives this message through its WindowProc function. This message frees any memory internally allocated for the window.
            關(guān)于WM_DESTROY與WM_NCDESTROY,從各種說明可以看出,一個大約充當(dāng)關(guān)閉操作啟動時的通知接口,一個大約充當(dāng)關(guān)閉操作完成時的通知接口。這也是我認為在DestroyWindow的處理流程中,第6條在第5條之后的原因。 
            另外,說明中有個值得一提的地方在于:WM_DESTROY用于釋放關(guān)聯(lián)到(associated to)窗口的已分配內(nèi)存對象,WM_NCDESTROY用于釋放內(nèi)部為窗口分配的(internally allocated for)內(nèi)存。 可以想象,后者應(yīng)當(dāng)指窗口的內(nèi)核數(shù)據(jù),但前者則有各種可能,菜單資源?GDI資源?異或是子窗口資源?這個就不好說了。 而且,根據(jù)這兩句話的表述,似乎這兩個清理操作是在消息的處理過程中發(fā)生的,然而顯然又不是由用戶來完成的工作,那么就應(yīng)當(dāng)是在DefWindowProc中完成的了。為什么不直接拿到Destroywindow中來執(zhí)行呢?
            ActiveX控件的銷毀
            銷毀控件的最好方法是銷毀宿主窗口。可以通過調(diào)用 CWindow::DestroyWindow 或 DestroyWindow API 顯式地進行銷毀,或者讓宿主窗口的父級窗口的毀壞導(dǎo)致其死亡,從而隱式地進行銷毀。這些方法的任何一種都將安全地銷毀寄宿的控件。請注意,CAxWindow 對象的毀壞"不會"導(dǎo)致基礎(chǔ)"AtlAxWin7"窗口的毀壞。 
            來自:http://technet.microsoft.com/zh-cn/query/cc468138

            posted on 2015-08-01 14:24 天下 閱讀(604) 評論(0)  編輯 收藏 引用 所屬分類: Win32

            <2011年6月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            久久无码AV中文出轨人妻| 看久久久久久a级毛片| 国产情侣久久久久aⅴ免费| 久久亚洲精品无码aⅴ大香| 久久e热在这里只有国产中文精品99 | 狠狠综合久久综合中文88| 波多野结衣中文字幕久久| 色88久久久久高潮综合影院| 伊人情人综合成人久久网小说| 狠狠精品干练久久久无码中文字幕 | 亚洲精品国产自在久久| 国产精品亚洲综合专区片高清久久久| 99久久这里只有精品| 国产成人精品白浆久久69| 精品久久久噜噜噜久久久| 久久精品国产亚洲av麻豆色欲| 精品伊人久久大线蕉色首页| 精品久久亚洲中文无码| 久久久一本精品99久久精品88| 2020久久精品亚洲热综合一本| 亚洲一区精品伊人久久伊人| 亚洲国产精品成人AV无码久久综合影院 | 亚洲综合伊人久久大杳蕉| 亚洲女久久久噜噜噜熟女| 久久久久人妻一区精品性色av| 久久久久亚洲AV无码网站| 国产一级持黄大片99久久| 秋霞久久国产精品电影院| 久久精品国产亚洲Aⅴ香蕉| 人妻丰满?V无码久久不卡| 7777久久久国产精品消防器材| 亚洲国产精品久久久天堂| 人妻无码久久一区二区三区免费| 久久99精品久久久久久久久久| 99久久精品毛片免费播放| 99久久国产综合精品五月天喷水 | 久久免费线看线看| 久久精品无码一区二区三区免费| 亚洲国产精品综合久久网络| 97精品国产97久久久久久免费| 精品999久久久久久中文字幕|