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;
}