⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcgpminiframewnd.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				GetWindowRect (&rect);
				rect.OffsetRect (ptOffset);
				MoveWindow (rect);

				m_dragFrameImpl.m_ptHot = ptMouse;
			}

			SetCursor (AfxGetApp ()->LoadStandardCursor (IDC_SIZEALL));
		}
		return;
	}

	CPoint ptScreen = point;
	ClientToScreen (&ptScreen);

	OnTrackCaptionButtons (ptScreen);
	CWnd::OnMouseMove(nFlags, point);
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::MoveDragFrame ()
{
	m_dragFrameImpl.MoveDragFrame (TRUE);
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnMoving(UINT fwSide, LPRECT pRect) 
{
	CWnd::OnMoving(fwSide, pRect);
	MoveMiniFrame ();
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnCheckRollState ()
{
	ASSERT_VALID (this);

	CBCGPDockManager* pDockManager = globalUtils.GetDockManager (GetParent ());
	ASSERT_VALID (pDockManager);	

	if (pDockManager->m_bLockUpdate)
	{
		return;
	}

	CRect rectClient;
	CRect rectWnd;

	GetWindowRect (rectWnd);
	GetClientRect (rectClient);

	BOOL bRollDown = IsRollDown ();
	BOOL bRollUp   = IsRollUp ();

	if (m_bRolledUp && bRollDown)
	{
		rectWnd.bottom = rectWnd.top + m_nHeightBeforeRollUp;
		SetWindowPos (NULL, rectWnd.left,  rectWnd.top, rectWnd.Width (), rectWnd.Height (),
					  SWP_NOZORDER  | SWP_NOACTIVATE);
		m_bRolledUp = FALSE;
	}
	
	if (!m_bRolledUp && bRollUp)
	{
		m_nHeightBeforeRollUp = rectWnd.Height ();
		rectWnd.bottom -= rectClient.Height ();
		SetWindowPos (NULL, rectWnd.left,  rectWnd.top, rectWnd.Width (), rectWnd.Height (),
					  SWP_NOZORDER  | SWP_NOACTIVATE);
		m_bRolledUp = TRUE;
	}
}
//--------------------------------------------------------------------------------------//
BOOL CBCGPMiniFrameWnd::IsRollDown () const
{
	CPoint ptMouse;
	GetCursorPos (&ptMouse);

	CRect rectWnd;
	GetWindowRect (rectWnd);

	const CWnd* pWnd = WindowFromPoint (ptMouse);
	return rectWnd.PtInRect (ptMouse) && (pWnd->GetSafeHwnd () == GetSafeHwnd ());
}
//--------------------------------------------------------------------------------------//
BOOL CBCGPMiniFrameWnd::IsRollUp () const
{
	CPoint ptMouse;
	GetCursorPos (&ptMouse);

	CRect rectWnd;
	GetWindowRect (rectWnd);

	return !rectWnd.PtInRect (ptMouse) && !m_bPinned;
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::AddControlBar (CBCGPBaseControlBar* pWnd)
{
	ASSERT_VALID (pWnd);

	if (m_hEmbeddedBar != pWnd->GetSafeHwnd ())
	{
		m_hEmbeddedBar = pWnd->GetSafeHwnd ();

		CString strText;
		pWnd->GetWindowText (strText);
		SetWindowText (strText);

		SetIcon (pWnd->GetIcon (FALSE), FALSE);
		SetIcon (pWnd->GetIcon (TRUE), TRUE);

		AddRemoveBarFromGlobalList (pWnd, TRUE);
		if (pWnd->CanBeClosed ())
		{
			if((pWnd->IsKindOf(RUNTIME_CLASS (CBCGPToolBar))))
			{
				CBCGPToolBar* pWndToolBar = (CBCGPToolBar*)pWnd;
				if(pWndToolBar->IsExistCustomizeButton() && pWndToolBar->IsAddRemoveQuickCustomize())
				{
					SetCaptionButtons (BCGP_CAPTION_BTN_CLOSE|BCGP_CAPTION_BTN_CUSTOMIZE);
				}else
				{
					SetCaptionButtons (BCGP_CAPTION_BTN_CLOSE); 
				}

			}else
			{
				SetCaptionButtons (BCGP_CAPTION_BTN_CLOSE); 
			}
		}

		if(pWnd->IsKindOf(RUNTIME_CLASS (CBCGPMenuBar)))
		{
			CBCGPToolBar* pWndToolBar = (CBCGPToolBar*)pWnd;
			if(pWndToolBar->IsExistCustomizeButton())
			{
				SetCaptionButtons (BCGP_CAPTION_BTN_CUSTOMIZE);
			}

		}
		OnSetRollUpTimer ();
	}
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnSetRollUpTimer ()
{
	CBCGPBaseControlBar* pBar = 
		DYNAMIC_DOWNCAST (CBCGPBaseControlBar, GetControlBar ());
	if (pBar != NULL && pBar->GetBCGStyle () & CBRS_BCGP_AUTO_ROLLUP)
	{
		SetRollUpTimer ();	
	}
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnKillRollUpTimer ()
{
	CBCGPBaseControlBar* pBar = 
		DYNAMIC_DOWNCAST (CBCGPBaseControlBar, GetControlBar ());

	if (pBar != NULL && (pBar->GetBCGStyle () & CBRS_BCGP_AUTO_ROLLUP) == 0 ||
		pBar == NULL)
	{
		KillRollupTimer ();
	}
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::SetRollUpTimer ()
{
	if (m_nRollTimerID == 0)
	{
		m_nRollTimerID = SetTimer (BCGP_CHECK_ROLL_STATE, m_nRollTimeOut, NULL);
		SetCaptionButtons (m_dwCaptionButtons | BCGP_CAPTION_BTN_PIN);
	}
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::KillRollupTimer ()
{
	if (m_nRollTimerID != 0)
	{
		KillTimer (m_nRollTimerID);
		m_nRollTimerID = 0;
		DWORD dwButtons = m_dwCaptionButtons & (~BCGP_CAPTION_BTN_PIN);
		SetCaptionButtons (dwButtons);
	}
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::RemoveControlBar (CBCGPBaseControlBar* pWnd, BOOL bDestroy,
										  BOOL bNoDelayedDestroy)
{
	ASSERT_VALID (this);

	m_bNoDelayedDestroy = bNoDelayedDestroy;

	AddRemoveBarFromGlobalList (pWnd, FALSE);

	pWnd->OnRemoveFromMiniFrame (this);

	if (m_hEmbeddedBar == pWnd->GetSafeHwnd ())
	{
		m_hEmbeddedBar = NULL;
	}

	OnKillRollUpTimer ();

	if (GetControlBarCount () == 0)
	{
		if (bDestroy)
		{
			DestroyWindow ();
		}
		else
		{
			PostMessage (BCGPM_CHECKEMPTYMINIFRAME);
		}
	}
}
//--------------------------------------------------------------------------------------//
BOOL CBCGPMiniFrameWnd::AddRemoveBarFromGlobalList (CBCGPBaseControlBar* pWnd, BOOL bAdd)
{
	ASSERT_VALID (pWnd);

	int nID = pWnd->GetDlgCtrlID ();

	if (nID != -1)
	{
		bAdd ? m_mapFloatingBars.SetAt (nID, pWnd->GetSafeHwnd ()) : m_mapFloatingBars.RemoveKey (nID);
	}
	else if (pWnd->IsKindOf (RUNTIME_CLASS (CBCGPBaseTabbedBar)))
	{
		CBCGPBaseTabbedBar* pTabbedBar = 
			DYNAMIC_DOWNCAST (CBCGPBaseTabbedBar, pWnd);

		int nTabsNum = pTabbedBar->GetTabsNum ();

		for (int i = 0; i < nTabsNum; i++)
		{
			CWnd* pNextWnd = pTabbedBar->FindBarByTabNumber (i, TRUE);
			ASSERT_VALID (pNextWnd);

			int nBarID = pNextWnd->GetDlgCtrlID ();
			
			if (nBarID == -1)
			{
				TRACE0 ("Tabbed control bar contains a bar with ID = -1\n");
				ASSERT (FALSE);
			}
			else
			{
				bAdd ?  m_mapFloatingBars.SetAt (nBarID, pNextWnd->GetSafeHwnd ()) : 
						m_mapFloatingBars.RemoveKey (nBarID);
			}
		}
	}
	else
	{
		return FALSE;
	}

	return TRUE;
}
//--------------------------------------------------------------------------------------//

void CBCGPMiniFrameWnd::ReplaceControlBar (CBCGPBaseControlBar* pBarOrg, 
										   CBCGPBaseControlBar* pBarReplaceWith)
{
	ASSERT_VALID (this);
	ASSERT_VALID (pBarOrg);
	ASSERT_VALID (pBarReplaceWith);
	ASSERT (pBarOrg != pBarReplaceWith);

	AddRemoveBarFromGlobalList (pBarOrg, FALSE);

	if (pBarOrg->GetSafeHwnd () == m_hEmbeddedBar)
	{
		m_hEmbeddedBar = pBarReplaceWith->GetSafeHwnd ();
	}

	AddRemoveBarFromGlobalList (pBarReplaceWith, TRUE);
}
//--------------------------------------------------------------------------------------//
CWnd* CBCGPMiniFrameWnd::GetControlBar () const
{
	ASSERT_VALID (this);
	
	return CWnd::FromHandlePermanent (m_hEmbeddedBar);
}
//--------------------------------------------------------------------------------------//
CWnd* CBCGPMiniFrameWnd::GetFirstVisibleBar () const
{
	if (GetVisibleBarCount () == 1)
	{
		return GetControlBar ();
	}
	return NULL;
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
{
	CRect rectBorderSize;
	CalcBorderSize (rectBorderSize);

	lpncsp->rgrc[0].top += m_nCaptionHeight + rectBorderSize.top;
	lpncsp->rgrc[0].bottom -= rectBorderSize.bottom;
	lpncsp->rgrc[0].left += rectBorderSize.left;
	lpncsp->rgrc[0].right -= rectBorderSize.right;
	
	CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnNcPaint() 
{
	CWindowDC dc(this); // device context for painting
	
	CDC*		pDC = &dc;
	BOOL		m_bMemDC = FALSE;
	CDC			dcMem;
	CBitmap		bmp;
	CBitmap*	pOldBmp = NULL;

	CRect rectWindow;
	GetWindowRect (rectWindow);
	CRect rect;
	rect.SetRect (0, 0, rectWindow.Width(), rectWindow.Height());

	if (dcMem.CreateCompatibleDC (&dc) &&
		bmp.CreateCompatibleBitmap (&dc, rect.Width (),
								  rect.Height ()))
	{
		//-------------------------------------------------------------
		// Off-screen DC successfully created. Better paint to it then!
		//-------------------------------------------------------------
		m_bMemDC = TRUE;
		pOldBmp = dcMem.SelectObject (&bmp);
		pDC = &dcMem;
	}
	
    // client area is not our bussiness :)
    CRect rcClient, rcBar;
    GetWindowRect(rcBar);

    GetClientRect(rcClient);
    ClientToScreen(rcClient);
    rcClient.OffsetRect(-rcBar.TopLeft());

    dc.ExcludeClipRect (rcClient);
	
	if (!m_rectRedraw.IsRectEmpty ())
	{
		CRgn rgn;
		rgn.CreateRectRgnIndirect (m_rectRedraw);

		dc.SelectClipRgn (&rgn);
	}

	// draw border
	OnDrawBorder (pDC);

	CRect rectCaption;
	GetCaptionRect (rectCaption);

	CBCGPDockManager* pDockManager = globalUtils.GetDockManager (GetParent ());
	ASSERT_VALID (pDockManager);	
	if (pDockManager->m_bLockUpdate)
	{
		rectCaption.SetRectEmpty ();	
	}

	// draw caption:
	GetCaptionRect (rectCaption);

	COLORREF clrText = CBCGPVisualManager::GetInstance ()->OnFillMiniFrameCaption (
							pDC, rectCaption, this, m_bActive);

	int xBtnsLeft = -1;
	int xBtnsRight = -1;
	for (POSITION pos = m_lstCaptionButtons.GetHeadPosition (); pos != NULL;)
	{
		CBCGPCaptionButton* pBtn = (CBCGPCaptionButton*) m_lstCaptionButtons.GetNext (pos);
		ASSERT_VALID (pBtn);

		if (pBtn->m_bLeftAlign)
		{
			if (xBtnsRight == -1)
			{
				xBtnsRight = pBtn->GetRect ().right + 2;
			}
			else
			{
				xBtnsRight = max (xBtnsRight, pBtn->GetRect ().right + 2);
			}
		}
		else
		{
			if (xBtnsLeft == -1)
			{
				xBtnsLeft = pBtn->GetRect ().left;
			}
			else
			{
				xBtnsLeft = min (xBtnsLeft, pBtn->GetRect ().left);
			}
		}
	}

	// Paint caption text:
	pDC->SetBkMode (TRANSPARENT);
	pDC->SetTextColor (clrText);

	CFont* pOldFont = pDC->SelectObject (&globalData.fontBold);
	ASSERT_VALID (pOldFont);

	CString strCaption = GetCaptionText ();

	CRect rectText = rectCaption;
	if (xBtnsLeft != -1)
	{
		rectText.right = xBtnsLeft;
	}
	if (xBtnsRight != -1)
	{
		rectText.left = xBtnsRight;
	}

	rectText.DeflateRect (2, 0);

	pDC->DrawText (strCaption, rectText, DT_LEFT | DT_SINGLELINE | DT_VCENTER);

	pDC->SelectObject (pOldFont);
	pDC->SelectClipRgn (NULL);

	// Paint caption buttons:
	OnDrawCaptionButtons (pDC);

	if (m_bMemDC)
	{
		//--------------------------------------
		// Copy the results to the on-screen DC:
		//-------------------------------------- 
		CRect rectClip;
		int nClipType = dc.GetClipBox (rectClip);
		if (nClipType != NULLREGION)
		{
			if (nClipType != SIMPLEREGION)
			{
				rectClip = rect;
			}

			dc.BitBlt (rectClip.left, rectClip.top, rectClip.Width(), rectClip.Height(),
						   &dcMem, rectClip.left, rectClip.top, SRCCOPY);
		}

		dcMem.SelectObject(pOldBmp);
	}

	CWnd::OnNcPaint ();
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnDrawBorder (CDC* pDC)
{
	ASSERT_VALID (pDC);
	
	CBCGPDockManager* pDockManager = globalUtils.GetDockManager (GetParent ());
	if (pDockManager == NULL)
	{
		return;
	}

	ASSERT_VALID (pDockManager);

	if (pDockManager->m_bLockUpdate)
	{
		return;
	}

	CRect rectWnd;
	GetWindowRect (&rectWnd);
	ScreenToClient (&rectWnd);

	CRect rectBorderSize;
	CalcBorderSize (rectBorderSize);
	
	rectWnd.OffsetRect (rectBorderSize.left, m_nCaptionHeight + rectBorderSize.top);

	CRect rectBorder = rectWnd;

	CBCGPToolBar* pToolBar = DYNAMIC_DOWNCAST (CBCGPToolBar, GetControlBar ());

	if (pToolBar != NULL)
	{
		pDC->FillRect (rectBorder, &globalData.brBtnFace);

		CBCGPVisualManager::GetInstance ()->OnDrawFloatingToolbarBorder (
			pDC, pToolBar, rectBorder, rectBorderSize);
		return;
	}

	CBCGPVisualManager::GetInstance ()->OnDrawMiniFrameBorder (
		pDC, this, rectBorder, rectBorderSize);
}
//--------------------------------------------------------------------------------------//

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -