EnumChildWindows Function
原创
©著作权归作者所有:来自51CTO博客作者alantop的原创作品,请联系作者获取转载授权,否则将追究法律责任
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
主框架调用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;
}