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

📄 bcgpminiframewnd.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		if (lpwndpos->flags & SWP_NOSIZE)
		{
			rect.SetRect (lpwndpos->x, lpwndpos->y, 
							lpwndpos->x + rectWnd.Width (), 
							lpwndpos->y + rectWnd.Height ());
		}
		else
		{
			rect.SetRect (lpwndpos->x, lpwndpos->y, 
							lpwndpos->x + lpwndpos->cx, 
							lpwndpos->y + lpwndpos->cy);
		}

		int captionHeight = GetCaptionHeight ();
		CRect rectDelta (captionHeight, captionHeight, captionHeight, 
							captionHeight);
		globalUtils.AdjustRectToWorkArea (rect, &rectDelta);
		lpwndpos->x = rect.left;
		lpwndpos->y = rect.top;
	}

	CWnd::OnWindowPosChanging(lpwndpos);
}
//--------------------------------------------------------------------------------------//
BOOL CBCGPMiniFrameWnd::MoveMiniFrame ()
{
	CWnd* pParent = GetParent ();
	
	if (pParent == NULL)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPFrameWnd)))
	{
		return ((CBCGPFrameWnd*) pParent)->OnMoveMiniFrame (this);
	}
	else if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPMDIFrameWnd)))
	{
		return ((CBCGPMDIFrameWnd*) pParent)->OnMoveMiniFrame (this);
	}
	else if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPOleIPFrameWnd)))
	{
		return ((CBCGPOleIPFrameWnd*) pParent)->OnMoveMiniFrame (this);
	}
	else if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPOleDocIPFrameWnd)))
	{
		return ((CBCGPOleDocIPFrameWnd*) pParent)->OnMoveMiniFrame (this);
	}
	else if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPMDIChildWnd)))
	{
		return ((CBCGPMDIChildWnd*) pParent)->OnMoveMiniFrame (this);
	}
	else if (pParent->IsKindOf (RUNTIME_CLASS (CBCGPOleCntrFrameWnd)))
	{
		return ((CBCGPOleCntrFrameWnd*) pParent)->OnMoveMiniFrame (this);
	}
	else 
	{
		ASSERT (FALSE);
	}
	return FALSE;
}
//--------------------------------------------------------------------------------------//
CString CBCGPMiniFrameWnd::GetCaptionText ()
{
	if (m_hEmbeddedBar == NULL)
	{
		return _T ("");
	}

	CString strCaption;
	CWnd* pEmbeddedWnd = CWnd::FromHandlePermanent (m_hEmbeddedBar);
	if (pEmbeddedWnd != NULL)
	{
		pEmbeddedWnd->GetWindowText (strCaption);
	}

	return strCaption;
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnTimer(UINT nIDEvent) 
{
	switch (nIDEvent)
	{
	case BCGP_DOCK_EVENT:
		{
			CBCGPDockManager* pDockManager = globalUtils.GetDockManager (GetParent ());
			ASSERT_VALID (pDockManager);
			pDockManager->OnMoveMiniFrame (this);
			return;
		}
	case BCGP_CHECK_ROLL_STATE:
		OnCheckRollState ();
		break;
	}

	CWnd::OnTimer(nIDEvent);
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::CalcBorderSize (CRect& rectBorderSize) const
{
	if (DYNAMIC_DOWNCAST (CBCGPToolBar, GetControlBar ()) != NULL)
	{
		rectBorderSize.SetRect (g_nToolbarBorderSize, g_nToolbarBorderSize, 
								g_nToolbarBorderSize, g_nToolbarBorderSize);
	}
	else
	{
		rectBorderSize.SetRect (GetSystemMetrics (SM_CXSIZEFRAME), 
								GetSystemMetrics (SM_CYSIZEFRAME),
								GetSystemMetrics (SM_CXSIZEFRAME),
								GetSystemMetrics (SM_CYSIZEFRAME));
	}
}
//--------------------------------------------------------------------------------------//
BOOL CBCGPMiniFrameWnd::OnNcActivate(BOOL bActive) 
{
	if ((GetStyle() & MFS_SYNCACTIVE) == 0)
	{
		bActive = (GetFocus () == this);
		if (m_bActive != bActive)
		{
			m_bActive = bActive;
			
			CBCGPDockManager* pDockManager = globalUtils.GetDockManager (GetParent ());
			if (pDockManager != NULL)
			{
				SendMessage(WM_NCPAINT);
			}
		}
	}
	else if(m_nFlags & WF_KEEPMINIACTIVE)
	{
		return FALSE;
	}

	return TRUE;
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::SetCaptionButtons (DWORD dwButtons)
{
	ASSERT_VALID (this);
	RemoveAllCaptionButtons ();

	if (dwButtons & BCGP_CAPTION_BTN_CLOSE)
	{
		CBCGPBaseControlBar* pBar = DYNAMIC_DOWNCAST (CBCGPBaseControlBar, GetControlBar ());
		if (pBar != NULL && pBar->CanBeClosed ())
		{
			AddButton (HTCLOSE);
		}
	}

	if (dwButtons & BCGP_CAPTION_BTN_PIN)
	{
		AddButton (HTMAXBUTTON);
	}

	if (dwButtons & BCGP_CAPTION_BTN_MENU)
	{
		AddButton (HTMINBUTTON);
	}

	if(dwButtons & BCGP_CAPTION_BTN_CUSTOMIZE)
	{
		AddButton(HTMENU_BCG); 
	}


	m_dwCaptionButtons = dwButtons;
	SetCaptionButtonsToolTips ();

	ArrangeCaptionButtons ();
	SendMessage (WM_NCPAINT);
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::AddButton (UINT nHit)
{
	ASSERT_VALID (this);

	CBCGPCaptionButton* pBtn = FindButton (nHit);

	if (pBtn == NULL)
	{
		switch (nHit) 
		{
			case HTMENU_BCG:
			{
				CBCGPCaptionMenuButton *pMenuBtn = new CBCGPCaptionMenuButton;
				pMenuBtn->m_bOSMenu = FALSE;
				pMenuBtn->m_nHit = HTMENU_BCG;
				m_lstCaptionButtons.AddHead (pMenuBtn);
				break;
			}

			default:
			pBtn = new CBCGPCaptionButton;
			m_lstCaptionButtons.AddHead (pBtn);
			pBtn->m_nHit = nHit;
			break;
		}
	}
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::RemoveButton (UINT nHit)
{
	ASSERT_VALID (this);

	for (POSITION pos = m_lstCaptionButtons.GetHeadPosition (); pos != NULL;)
	{
		POSITION posSave = pos;

		CBCGPCaptionButton* pBtn = (CBCGPCaptionButton*) m_lstCaptionButtons.GetNext (pos);
		ASSERT_VALID (pBtn);

		if (pBtn->m_nHit == nHit)
		{
			m_lstCaptionButtons.RemoveAt (posSave);
			delete pBtn;
			break;
		}
	}

	ArrangeCaptionButtons ();
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::ReplaceButton (UINT nHit, UINT nHitNew)
{
	ASSERT_VALID (this);

	CBCGPCaptionButton* pBtn = FindButton (nHit);
	if (pBtn != NULL)
	{
		pBtn->m_nHit = nHitNew;
	}
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::ShowButton (UINT nHit, BOOL bShow)
{
	ASSERT_VALID (this);
	CBCGPCaptionButton* pBtn = FindButton (nHit);
	if (pBtn != NULL)
	{
		pBtn->m_bHidden = bShow;
		ArrangeCaptionButtons ();
	}
}
//--------------------------------------------------------------------------------------//
CBCGPCaptionButton* CBCGPMiniFrameWnd::FindButton (UINT uiHit) const
{
	ASSERT_VALID (this);

	for (POSITION pos = m_lstCaptionButtons.GetHeadPosition (); pos != NULL;)
	{
		CBCGPCaptionButton* pBtn = (CBCGPCaptionButton*) m_lstCaptionButtons.GetNext (pos);
		ASSERT_VALID (pBtn);

		if (pBtn->GetHit () == uiHit)
		{
			return pBtn;
		}
	}

	return NULL;
}
//--------------------------------------------------------------------------------------//
CBCGPCaptionButton* CBCGPMiniFrameWnd::FindButton (CPoint point) const
{
	ASSERT_VALID (this);

	CRect rectWnd;
	GetWindowRect (&rectWnd);

	for (POSITION pos = m_lstCaptionButtons.GetHeadPosition (); pos != NULL;)
	{
		CBCGPCaptionButton* pBtn = (CBCGPCaptionButton*) m_lstCaptionButtons.GetNext (pos);
		ASSERT_VALID (pBtn);

		CRect rectBtn = pBtn->GetRect ();
		rectBtn.OffsetRect (rectWnd.TopLeft ());

		if (rectBtn.PtInRect (point))
		{
			return pBtn;
		}
	}

	return NULL;
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::RemoveAllCaptionButtons ()
{
	ASSERT_VALID (this);

	m_dwCaptionButtons = 0;
	
	while (!m_lstCaptionButtons.IsEmpty ())
	{
		delete m_lstCaptionButtons.RemoveHead ();
	}
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::UpdateTooltips ()
{
	// Update tool area for the tooltips:
	if (m_ToolTip.GetSafeHwnd() != NULL)
	{
		CRect rcBar;
		GetWindowRect(rcBar);
		ScreenToClient (rcBar);
		int i = 0;
		for (POSITION pos = m_lstCaptionButtons.GetHeadPosition (); pos != NULL; i++)
		{
			CBCGPCaptionButton* pBtn = (CBCGPCaptionButton*) m_lstCaptionButtons.GetNext (pos);
			ASSERT_VALID (pBtn);

			if (i < m_ToolTip.GetToolCount())
			{
				CRect rectTT;
				rectTT.SetRectEmpty ();
				if (!pBtn->m_bHidden)
				{
					rectTT = pBtn->GetRect ();
					rectTT.OffsetRect (rcBar.TopLeft());
				}
				m_ToolTip.SetToolRect (this, i + 1, rectTT);
			}
		}
	}
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::ArrangeCaptionButtons ()
{
	ASSERT_VALID (this);

	CRect rectCaption;
	GetCaptionRect (rectCaption);

	CSize btnSize = CBCGPCaptionButton::GetSize ();
	CPoint ptOrgRight (rectCaption.right - g_nCaptionButtonMargin, 
					rectCaption.top + (rectCaption.Height () - btnSize.cy) / 2);
	CPoint ptOrgLeft (rectCaption.left + g_nCaptionButtonMargin, 
					rectCaption.top + (rectCaption.Height () - btnSize.cy) / 2);

	int i = 0;
	for (POSITION pos = m_lstCaptionButtons.GetTailPosition (); pos != NULL; i++)
	{
		CBCGPCaptionButton* pBtn = (CBCGPCaptionButton*) m_lstCaptionButtons.GetPrev (pos);
		ASSERT_VALID (pBtn);

		if (!pBtn->m_bHidden)
		{
			if (pBtn->m_bLeftAlign)
			{
				pBtn->Move (ptOrgLeft);
				ptOrgLeft.x += btnSize.cx;
				ptOrgLeft.x += g_nCaptionButtonSpacing;
			}
			else
			{
				ptOrgRight.x -= btnSize.cx;
				pBtn->Move (ptOrgRight);
				ptOrgRight.x -= g_nCaptionButtonSpacing;
			}
		}
	}

	UpdateTooltips ();
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::RedrawCaptionButton (CBCGPCaptionButton* pBtn)
{
	ASSERT_VALID(this);

	if (pBtn ==	NULL)
	{
		return;
	}

	ASSERT_VALID (pBtn);

	m_rectRedraw = pBtn->GetRect ();
	SendMessage (WM_NCPAINT);
	m_rectRedraw.SetRectEmpty ();

	UpdateWindow ();
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::CloseMiniFrame ()
{
	ShowWindow (SW_HIDE);
	
	if (m_hEmbeddedBar != NULL)
	{
		CWnd* pEmbeddedWnd = CWnd::FromHandlePermanent (m_hEmbeddedBar);
		if (pEmbeddedWnd != NULL)
		{
			pEmbeddedWnd->ShowWindow (SW_HIDE);
		}
	}
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnNcLButtonDblClk(UINT nHitTest, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CWnd::OnNcLButtonDblClk(nHitTest, point);
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	
	CPoint ptScreen = point;
	ClientToScreen (&ptScreen);

	CBCGPCaptionButton* pBtn = FindButton (ptScreen);
	if (pBtn != NULL)
	{
		CWnd::OnLButtonDblClk(nFlags, point);
		return;
	}

	CBCGPControlBar* pBar = DYNAMIC_DOWNCAST (CBCGPControlBar, CWnd::FromHandlePermanent (m_hEmbeddedBar));	

	if (pBar != NULL && pBar->GetEnabledAlignment () & CBRS_ALIGN_ANY)
	{
		SaveRecentFloatingState ();

		if (pBar->DockControlBar (pBar, NULL, DM_DBL_CLICK))
		{
			// was destroyed if DockControlBar returned TRUE
			return;
		}
	}

	CWnd::OnLButtonDblClk(nFlags, point);
}
//--------------------------------------------------------------------------------------//
BOOL CBCGPMiniFrameWnd::PreCreateWindow(CREATESTRUCT& cs) 
{
	cs.style |= MFS_SYNCACTIVE;
	return CWnd::PreCreateWindow(cs);
}
//--------------------------------------------------------------------------------------//
BOOL CBCGPMiniFrameWnd::OnNcCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (!CWnd::OnNcCreate(lpCreateStruct))
		return FALSE;
	
	if (GetStyle() & MFS_SYNCACTIVE)
	{
		// syncronize activation state with top level parent
		CWnd* pParentWnd = GetTopLevelParent();
		ASSERT(pParentWnd != NULL);
		CWnd* pActiveWnd = GetForegroundWindow();
		BOOL bActive = (pParentWnd == pActiveWnd) ||
			(pParentWnd->GetLastActivePopup() == pActiveWnd &&
			 pActiveWnd->SendMessage(WM_FLOATSTATUS, FS_SYNCACTIVE) != 0);

		// the WM_FLOATSTATUS does the actual work
		SendMessage(WM_FLOATSTATUS, bActive ? FS_ACTIVATE : FS_DEACTIVATE);
	}
	
	return TRUE;
}
//--------------------------------------------------------------------------------------//
LRESULT CBCGPMiniFrameWnd::OnFloatStatus(WPARAM wParam, LPARAM)
{
	// these asserts make sure no conflicting actions are requested
	ASSERT(!((wParam & FS_SHOW) && (wParam & FS_HIDE)));
	ASSERT(!((wParam & FS_ENABLE) && (wParam & FS_DISABLE)));
	ASSERT(!((wParam & FS_ACTIVATE) && (wParam & FS_DEACTIVATE)));

	// FS_SYNCACTIVE is used to detect MFS_SYNCACTIVE windows
	LRESULT lResult = 0;
	if ((GetStyle() & MFS_SYNCACTIVE) && (wParam & FS_SYNCACTIVE))
		lResult = 1;

	if (wParam & (FS_SHOW|FS_HIDE))
	{
		SetWindowPos(NULL, 0, 0, 0, 0,
			((wParam & FS_SHOW) ? SWP_SHOWWINDOW : SWP_HIDEWINDOW) | SWP_NOZORDER |
			SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
	}
	if (wParam & (FS_ENABLE|FS_DISABLE))
		EnableWindow((wParam & FS_ENABLE) != 0);

	if ((wParam & (FS_ACTIVATE|FS_DEACTIVATE)) &&
		GetStyle() & MFS_SYNCACTIVE)
	{
		ModifyStyle(MFS_SYNCACTIVE, 0);
		SendMessage(WM_NCACTIVATE, (wParam & FS_ACTIVATE) != 0);
		ModifyStyle(0, MFS_SYNCACTIVE);
	}

⌨️ 快捷键说明

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