The EnumChildWindows function enumerates the child windows that belong to the specified parent window by passing the handle to each child window, in turn, to an application-defined callback function. EnumChildWindows continues until the last child window is enumerated or the callback function returns FALSE.
主框架调用EnumChildWindows让每个子窗口都去执行SendPrepareToClose去做每个子窗口的清理工作。
BOOL CMainFrame::DestroyWindow()
{
::EnumChildWindows(m_hWnd, SendPrepareToClose, 0);
return CMDIFrameWnd::DestroyWindow();
}
static BOOL CALLBACK SendPrepareToClose(HWND hWnd, LPARAM)
{
CWnd* pWnd = CWnd::FromHandlePermanent(hWnd);
if (pWnd != NULL)
{
pWnd->SendMessage(WM_USER_PREPARE_TO_CLOSE);
if (pWnd->GetWindow(GW_CHILD) != NULL)
::EnumChildWindows(pWnd->m_hWnd, SendPrepareToClose, 0);
}
return TRUE;
}
本文介绍如何使用EnumChildWindows函数枚举指定父窗口的所有子窗口,并通过回调函数SendPrepareToClose执行子窗口的清理工作。清理过程涉及递归地处理所有子窗口及其子代。
1186

被折叠的 条评论
为什么被折叠?



