static void on_view(mfc_term_view *view) { if (view && IsWindow(view->m_hWnd)) { CMDIFrameWnd *fw = (CMDIFrameWnd *)(the_boss.m_pMainWnd); if (view->is_visible) { CMDIChildWnd *cw = (CMDIChildWnd *)fw->GetActiveFrame(); if (view == cw->GetActiveView()) fw->MDINext(); view->GetParent()->ShowWindow(SW_HIDE); } else { view->GetParent()->ShowWindow(SW_SHOW); fw->MDIActivate(view->GetParent()); } view->is_visible = !view->is_visible; SendMessage(fw->m_hWndMDIClient, WM_MDIREFRESHMENU, 0, 0); } }
void CMDIChildWnd::ActivateFrame(int nCmdShow) { BOOL bVisibleThen = (GetStyle() & WS_VISIBLE) != 0; CMDIFrameWnd* pFrameWnd = GetMDIFrame(); ASSERT_VALID(pFrameWnd); // determine default show command if (nCmdShow == -1) { // get maximized state of frame window (previously active child) BOOL bMaximized; pFrameWnd->MDIGetActive(&bMaximized); // convert show command based on current style DWORD dwStyle = GetStyle(); if (bMaximized || (dwStyle & WS_MAXIMIZE)) nCmdShow = SW_SHOWMAXIMIZED; else if (dwStyle & WS_MINIMIZE) nCmdShow = SW_SHOWMINIMIZED; } // finally, show the window CFrameWnd::ActivateFrame(nCmdShow); // update the Window menu to reflect new child window CMDIFrameWnd* pFrame = GetMDIFrame(); ::SendMessage(pFrame->m_hWndMDIClient, WM_MDIREFRESHMENU, 0, 0); // Note: Update the m_bPseudoInactive flag. This is used to handle the // last MDI child getting hidden. Windows provides no way to deactivate // an MDI child window. BOOL bVisibleNow = (GetStyle() & WS_VISIBLE) != 0; if (bVisibleNow == bVisibleThen) return; if (!bVisibleNow) { // get current active window according to Windows MDI HWND hWnd = (HWND)::SendMessage(pFrameWnd->m_hWndMDIClient, WM_MDIGETACTIVE, 0, 0); if (hWnd != m_hWnd) { // not active any more -- window must have been deactivated ASSERT(!m_bPseudoInactive); return; } // check next window ASSERT(hWnd != NULL); pFrameWnd->MDINext(); // see if it has been deactivated now... hWnd = (HWND)::SendMessage(pFrameWnd->m_hWndMDIClient, WM_MDIGETACTIVE, 0, 0); if (hWnd == m_hWnd) { // still active -- fake deactivate it ASSERT(hWnd != NULL); ::SendMessage(pFrameWnd->m_hWndMDIClient, WM_MDIACTIVATE, (WPARAM)m_hWnd, NULL); m_bPseudoInactive = TRUE; // so MDIGetActive returns NULL } } else if (m_bPseudoInactive) { // if state transitioned from not visible to visible, but // was pseudo deactivated -- send activate notify now ::SendMessage(pFrameWnd->m_hWndMDIClient, WM_MDIACTIVATE, NULL, (LPARAM)m_hWnd); ASSERT(!m_bPseudoInactive); // should get set in OnMDIActivate! } }