void CMonitorWnd::SetActivePage(CWnd *pWnd, BOOL bRepaint) { if(pWnd == NULL || !IsWindow(pWnd->m_hWnd)) { return; } POSITION pos = m_PageList.Find(pWnd); if(pos == NULL) { TRACE("__This Window is not a member of container, the operation will terminate.\n"); return; } if(m_bDrawActive) { DrawActivePage(FALSE); } m_bDrawActive = TRUE; m_pActivePage = pWnd; if(bRepaint) { UpdateWnd(); } if(m_bDrawActive) { DrawActivePage(TRUE); } }
void CMonitorWnd::UpdateWnd() { if(!IsWindowVisible() || IsIconic()) { return; } CRect rectContainer; GetClientRect(&rectContainer); GetShowRect(&rectContainer); // rectContainer.DeflateRect(1,1); if(m_bAutoAdjustPos) { AdjustRect(&rectContainer); } if(m_bMultiScreen) { CRect rect; int nCount = m_PageList.GetCount(); int i = 0; for(POSITION pos = m_PageList.GetHeadPosition(); pos != NULL; i++) { CWnd *pWnd = m_PageList.GetNext(pos); rect = rectContainer; CalcPageRect(&rect, i, nCount); rect.DeflateRect(WINDOW_PAGE_SPACE, WINDOW_PAGE_SPACE, WINDOW_PAGE_SPACE, WINDOW_PAGE_SPACE); // 窗口之间的间隔 pWnd->MoveWindow(&rect); pWnd->ShowWindow(SW_SHOW); } } else { for(POSITION pos = m_PageList.GetHeadPosition(); pos!=NULL;) { CWnd *pWnd = m_PageList.GetNext(pos); if(pWnd == m_pActivePage) { CRect rect = rectContainer; rect.DeflateRect(WINDOW_PAGE_SPACE, WINDOW_PAGE_SPACE, WINDOW_PAGE_SPACE, WINDOW_PAGE_SPACE); pWnd->MoveWindow(&rect); pWnd->ShowWindow(SW_SHOW); } else { pWnd->MoveWindow(rectContainer.right+1, rectContainer.bottom+1, 1, 1); // pWnd->ShowWindow(SW_HIDE); } } } if(m_bDrawActive && m_PageList.GetCount() > 1) { DrawActivePage(TRUE); } }
////////////////////////////////////////////////// // draw active page void CBSWndContainer::SetDrawActivePage(BOOL bFlag,COLORREF clrTopLeft,COLORREF clrBottomRight) { if(m_bDrawActive==bFlag) return; if(bFlag) { m_clrTopLeft=clrTopLeft; m_clrBottomRight=clrBottomRight; } m_bDrawActive=bFlag; DrawActivePage(bFlag); }
/////////////////////////////////////////////////// // call this function to page wnds,when // the window is resized. void CBSWndContainer::UpdateWnd() { if(!IsWindowVisible()||IsIconic()) return; ///////////////////// //计算显示总区域 //得到窗口的设备坐标 CRect rtContainer; GetClientRect(&rtContainer); GetShowRect(&rtContainer); rtContainer.DeflateRect(1,1); //调整Container位置 if(m_bAutoAdjustPos) AdjustRect(&rtContainer); ///////////////////// // if(m_bMultiScreen) { //多屏状态 CRect rt; int nCount=m_PageList.GetCount(); int i=0; for(POSITION pos=m_PageList.GetHeadPosition();pos!=NULL;) { CWnd *p=m_PageList.GetNext(pos); rt=rtContainer; CalcPageRect(&rt,i,nCount); rt.DeflateRect(WINDOW_SPACE,WINDOW_SPACE,WINDOW_SPACE,WINDOW_SPACE); //窗口之间的间隔 p->MoveWindow(&rt); p->ShowWindow(SW_SHOW); i++; } if( m_bDrawActive && m_PageList.GetCount()>1 ) DrawActivePage(TRUE); } else { //单屏状态 for(POSITION pos=m_PageList.GetHeadPosition();pos!=NULL;) { CWnd *p=m_PageList.GetNext(pos); if(p==m_pActivePage) p->MoveWindow(&rtContainer); else { if(m_bFullScreen) p->MoveWindow(0,0,1,1); else p->MoveWindow(rtContainer.right+1,rtContainer.bottom+1,1,1); } } } }
/////////////////////////////////////////////////// // call this function to set a page to be active // page. void CBSWndContainer::SetActivePage(CWnd *pWnd, BOOL bRepaint) { // check parameter if( !pWnd || !IsWindow(pWnd->m_hWnd) ) return; // if pWnd is the Active Page, return if( m_pActivePage==pWnd ) return; // check list POSITION pos=m_PageList.Find(pWnd); if(pos==NULL) { TRACE("__This Window is not a member of container, the operation will terminate.\n"); return; } if(bRepaint) UpdateWnd(); if( m_bDrawActive ) DrawActivePage(FALSE); m_pActivePage=pWnd; if( m_bDrawActive ) DrawActivePage(TRUE); }
/////////////////////////////////////////////////// // call this function to add a page wnd to // container. if success retrun TRUE,else return // FALSE. BOOL CBSWndContainer::AddPage(CWnd *pWnd, BOOL bRepaint) { // check parameter if( !pWnd || !IsWindow(pWnd->m_hWnd) ) return FALSE; // check list POSITION pos=m_PageList.Find(pWnd); if(pos!=NULL) { TRACE("This Window has been added to container, the operation will terminate.\n"); return TRUE; } // added page m_PageList.AddTail(pWnd); if( m_bDrawActive ) DrawActivePage(FALSE); // reset active page SetActivePage(pWnd, bRepaint); return TRUE; }
BOOL CMonitorWnd::AddPage(CWnd *pWnd, BOOL bRepaint) { if(pWnd == NULL || !IsWindow(pWnd->m_hWnd)) { return FALSE; } POSITION pos = m_PageList.Find(pWnd); if(pos != NULL) { return TRUE; } m_PageList.AddTail(pWnd); if(m_bDrawActive) { DrawActivePage(FALSE); } // SetActivePage(pWnd, bRepaint); return TRUE; }
void CMonitorWnd::CleanActivePage() { DrawActivePage(FALSE); m_bDrawActive = FALSE; }