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

📄 bcgpoutlookbarpane.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
void CBCGPOutlookBarPane::OnNcCalcSize(BOOL /*bCalcValidRects*/, NCCALCSIZE_PARAMS FAR* lpncsp) 
{
	CRect rect; 
	rect.SetRectEmpty();

	CBCGPControlBar::CalcInsideRect(rect, FALSE);

	// adjust non-client area for border space
	lpncsp->rgrc[0].left += rect.left;
	lpncsp->rgrc[0].top += rect.top;
	lpncsp->rgrc[0].right += rect.right;
	lpncsp->rgrc[0].bottom += rect.bottom;
}
//*************************************************************************************
void CBCGPOutlookBarPane::SetBackImage (UINT uiImageID)
{
	if (m_uiBackImageId == uiImageID)
	{
		return;
	}

	m_bDrawShadedHighlight = FALSE;
	if (m_bmpBack.GetCount () > 0)
	{
		m_bmpBack.Clear ();
	}

	m_uiBackImageId = 0;
	if (uiImageID != 0)
	{
		HBITMAP hbmp = (HBITMAP) ::LoadImage (
				AfxGetResourceHandle (),
				MAKEINTRESOURCE (uiImageID),
				IMAGE_BITMAP,
				0, 0,
				LR_CREATEDIBSECTION | LR_LOADMAP3DCOLORS);
		if (hbmp != NULL)
		{
			BITMAP bitmap;
			::GetObject (hbmp, sizeof (BITMAP), (LPVOID) &bitmap);

			m_bmpBack.SetImageSize (CSize (bitmap.bmWidth, bitmap.bmHeight));
			m_bmpBack.AddImage (hbmp);
			m_uiBackImageId = uiImageID;
		}

		m_bDrawShadedHighlight = (globalData.m_nBitsPerPixel > 8);	// For 16 bits or greater
	}

	if (GetSafeHwnd () != NULL)
	{
		Invalidate ();
		UpdateWindow ();
	}
}
//*************************************************************************************
void CBCGPOutlookBarPane::SetBackColor (COLORREF color)
{
	m_clrBackColor = color;
	if (GetSafeHwnd () != NULL)
	{
		Invalidate ();
		UpdateWindow ();
	}
}
//*************************************************************************************
void CBCGPOutlookBarPane::SetTransparentColor (COLORREF color)
{
	m_clrTransparentColor = color;
	if (GetSafeHwnd () != NULL)
	{
		m_Images.SetTransparentColor (m_clrTransparentColor);
		Invalidate ();
		UpdateWindow ();
	}
}
//*************************************************************************************
void CBCGPOutlookBarPane::OnSysColorChange() 
{
	CBCGPToolBar::OnSysColorChange();
	
	m_clrBackColor = globalData.clrBtnShadow;

	if (m_uiBackImageId != 0)
	{
		int uiImage = m_uiBackImageId;
		m_uiBackImageId = (UINT) -1;

		SetBackImage (uiImage);
	}
	else
	{
		m_clrRegText = globalData.clrWindow;
		Invalidate ();
	}
}
//*****************************************************************************************
void CBCGPOutlookBarPane::AdjustLocations ()
{
	if (GetSafeHwnd () == NULL)
	{
		return;
	}

	ASSERT_VALID(this);


	CSize sizeBtn = CMenuImages::Size () + CSize (4, 4);

	CClientDC dc (this);
	CFont* pOldFont = dc.SelectObject (&globalData.fontRegular);

	CRect rectClient;
	GetClientRect (rectClient);

	CSize sizeDefault = CSize (rectClient.Width () - 2, m_csImage.cy);

	if (IsButtonExtraSizeAvailable ())
	{
		sizeDefault += CBCGPVisualManager::GetInstance ()->GetButtonExtraBorder ();
	}


	int iOffset = rectClient.top - m_iScrollOffset + m_nExtraSpace;

	if (m_iFirstVisibleButton > 0 && 
		sizeBtn.cx <= rectClient.Width () - SCROLL_BUTTON_OFFSET && 
		sizeBtn.cy <= rectClient.Height () - SCROLL_BUTTON_OFFSET)
	{
		int nAdjButton = SCROLL_BUTTON_OFFSET;

		m_btnUp.SetWindowPos (NULL, 
				rectClient.right - sizeBtn.cx - nAdjButton,
				rectClient.top + SCROLL_BUTTON_OFFSET,
				-1, -1,
				SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);

		m_btnUp.ShowWindow (SW_SHOWNOACTIVATE);
	}
	else
	{
		m_btnUp.ShowWindow (SW_HIDE);
	}

	for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;)
	{
		CBCGPOutlookButton* pButton = (CBCGPOutlookButton*) m_Buttons.GetNext (pos);
		ASSERT (pButton != NULL);

		pButton->m_bTextBelow = m_bTextLabels;
		pButton->m_sizeImage = m_csImage;

		CSize sizeButton = pButton->OnCalculateSize (&dc, sizeDefault, FALSE);

		CRect rectButton;

		int nWidth = rectClient.Width () - 1;
		sizeButton.cx = min (nWidth, sizeButton.cx);

		rectButton = CRect (
			CPoint (rectClient.left + (nWidth - sizeButton.cx) / 2, iOffset), 
			sizeButton);
		iOffset = rectButton.bottom + m_nExtraSpace;

		pButton->SetRect (rectButton);
	}

	m_bScrollDown = (iOffset > rectClient.bottom);

	if (m_bScrollDown && 
		sizeBtn.cx <= rectClient.Width () - SCROLL_BUTTON_OFFSET && 
		sizeBtn.cy <= rectClient.Height () - SCROLL_BUTTON_OFFSET)
	{
		int nAdjButton = SCROLL_BUTTON_OFFSET;

		m_btnDown.SetWindowPos (&wndTop, rectClient.right - sizeBtn.cx - nAdjButton,
					rectClient.bottom - sizeBtn.cy - SCROLL_BUTTON_OFFSET,
					-1, -1,
					SWP_NOSIZE | SWP_NOACTIVATE);

		m_btnDown.ShowWindow (SW_SHOWNOACTIVATE);
	}
	else
	{
		m_btnDown.ShowWindow (SW_HIDE);
	}

	dc.SelectObject (pOldFont);

	m_btnUp.RedrawWindow ();
	m_btnDown.RedrawWindow ();

	OnMouseLeave (0, 0);
	UpdateTooltips ();
}
//*************************************************************************************
void CBCGPOutlookBarPane::DoPaint(CDC* pDCPaint)
{
	ASSERT_VALID(this);
	ASSERT_VALID(pDCPaint);

	CRect rectClip;

	GetClientRect (rectClip);

	CRect rectClient;
	GetClientRect (rectClient);

	CDC*		pDC = pDCPaint;
	BOOL		m_bMemDC = FALSE;
	CDC			dcMem;
	CBitmap		bmp;
	CBitmap*	pOldBmp = NULL;

	if (dcMem.CreateCompatibleDC (pDCPaint) &&
		bmp.CreateCompatibleBitmap (pDCPaint, rectClient.Width (),
								  rectClient.Height ()))
	{
		//-------------------------------------------------------------
		// Off-screen DC successfully created. Better paint to it then!
		//-------------------------------------------------------------
		m_bMemDC = TRUE;
		pOldBmp = dcMem.SelectObject (&bmp);
		pDC = &dcMem;
	}

	CBCGPVisualManager::GetInstance ()->OnFillBarBackground (pDC, this, rectClient, rectClient);

	if (!m_Buttons.IsEmpty ())
	{
		pDC->SetTextColor (globalData.clrBtnText);
		pDC->SetBkMode (TRANSPARENT);

		CBCGPDrawState ds;
		if (!m_Images.PrepareDrawImage (ds))
		{
			ASSERT (FALSE);
			return;     // something went wrong
		}

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

		//--------------
		// Draw buttons:
		//--------------
		int iButton = 0;
		for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL; iButton ++)
		{
			CBCGPOutlookButton* pButton = (CBCGPOutlookButton*) m_Buttons.GetNext (pos);
			ASSERT_VALID (pButton);

			CRect rect = pButton->Rect ();

			BOOL bHighlighted = FALSE;

			if (IsCustomizeMode () && !m_bLocked)
			{
				bHighlighted = FALSE;
			}
			else
			{
				bHighlighted = ((iButton == m_iHighlighted ||
								iButton == m_iButtonCapture) &&
								(m_iButtonCapture == -1 ||
								iButton == m_iButtonCapture));
			}

			CRect rectInter;
			if (rectInter.IntersectRect (rect, rectClip))
			{
				pButton->OnDraw (pDC, rect, &m_Images, FALSE, IsCustomizeMode (),
								bHighlighted);
			}
		}

		//-------------------------------------------------------------
		// Highlight selected button in the toolbar customization mode:
		//-------------------------------------------------------------
		if (m_iSelected >= m_Buttons.GetCount ())
		{
			m_iSelected = -1;
		}

		if (IsCustomizeMode () && m_iSelected >= 0 && !m_bLocked)
		{
			CBCGPToolbarButton* pSelButton = GetButton (m_iSelected);
			ASSERT (pSelButton != NULL);

			if (pSelButton != NULL && pSelButton->CanBeStored ())
			{
				CRect rectDrag = pSelButton->Rect ();
				if (pSelButton->GetHwnd () != NULL)
				{
					rectDrag.InflateRect (0, 1);
				}

				pDC->DrawDragRect (&rectDrag, CSize (2, 2), NULL, CSize (2, 2));
			}
		}

		if (IsCustomizeMode () && m_iDragIndex >= 0 && !m_bLocked)
		{
			DrawDragMarker (pDC);
		}

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

		m_Images.EndDrawImage (ds);
	}

	if (m_bMemDC)
	{
		//--------------------------------------
		// Copy the results to the on-screen DC:
		//-------------------------------------- 
		pDCPaint->BitBlt (rectClip.left, rectClip.top, rectClip.Width(), rectClip.Height(),
					   &dcMem, rectClip.left, rectClip.top, SRCCOPY);

		dcMem.SelectObject(pOldBmp);
	}
}
//****************************************************************************************
DROPEFFECT CBCGPOutlookBarPane::OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
	CBCGPToolbarButton* pButton = CBCGPToolbarButton::CreateFromOleData (pDataObject);
	if (pButton == NULL)
	{
		return DROPEFFECT_NONE;
	}

	BOOL bAllowDrop = pButton->IsKindOf (RUNTIME_CLASS (CBCGPOutlookButton));
	delete pButton;

	if (!bAllowDrop)
	{
		return DROPEFFECT_NONE;
	}

	CRect rectUp;
	m_btnUp.GetWindowRect (rectUp);
	ScreenToClient (rectUp);

	if (rectUp.PtInRect (point))
	{
		ScrollUp ();
		return DROPEFFECT_NONE;
	}

	CRect rectDown;
	m_btnDown.GetWindowRect (rectDown);
	ScreenToClient (rectDown);

	if (rectDown.PtInRect (point))
	{
		ScrollDown ();
		return DROPEFFECT_NONE;
	}

	return CBCGPToolBar::OnDragOver (pDataObject, dwKeyState, point);
}
//***************************************************************************************
CBCGPToolbarButton* CBCGPOutlookBarPane::CreateDroppedButton (COleDataObject* pDataObject)
{
	CBCGPToolbarButton* pButton = CBCGPToolBar::CreateDroppedButton (pDataObject);
	ASSERT (pButton != NULL);

	CBCGPOutlookButton* pOutlookButton = DYNAMIC_DOWNCAST (CBCGPOutlookButton, pButton);
	if (pOutlookButton == NULL)
	{
		delete pButton;

		ASSERT (FALSE);
		return NULL;
	}

	return pButton;
}
//***************************************************************************************
BOOL CBCGPOutlookBarPane::EnableContextMenuItems (CBCGPToolbarButton* pButton, CMenu* pPopup)
{
	ASSERT_VALID (pButton);
	ASSERT_VALID (pPopup);

	if (IsCustomizeMode ())
	{
		pPopup->EnableMenuItem (ID_BCGBARRES_TOOLBAR_IMAGE, MF_GRAYED | MF_BYCOMMAND);
		pPopup->EnableMenuItem (ID_BCGBARRES_TOOLBAR_TEXT, MF_GRAYED | MF_BYCOMMAND);
		pPopup->EnableMenuItem (ID_BCGBARRES_TOOLBAR_IMAGE_AND_TEXT, MF_GRAYED | MF_BYCOMMAND);
		pPopup->EnableMenuItem (ID_BCGBARRES_TOOLBAR_APPEARANCE, MF_GRAYED | MF_BYCOMMAND);
		pPopup->EnableMenuItem (ID_BCGBARRES_TOOLBAR_START_GROUP, MF_GRAYED | MF_BYCOMMAND);
		pPopup->EnableMenuItem (ID_BCGBARRES_TOOLBAR_RESET, MF_GRAYED | MF_BYCOMMAND);
		pPopup->EnableMenuItem (ID_BCGBARRES_COPY_IMAGE, MF_GRAYED | MF_BYCOMMAND);
	}

	CBCGPToolBar::EnableContextMenuItems (pButton, pPopup);
	return TRUE;
}
//**************************************************************************************
BOOL CBCGPOutlookBarPane::PreTranslateMessage(MSG* pMsg) 
{
   	switch (pMsg->message)
	{
	case WM_LBUTTONUP:
		KillTimer (idScrollUp);
		KillTimer (idScrollDn);

	case WM_LBUTTONDOWN:
	case WM_MOUSEMOVE:
		{
			CPoint ptCursor;
			::GetCursorPos (&ptCursor);
			ScreenToClient (&ptCursor);

			CRect rect;

⌨️ 快捷键说明

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