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

📄 bcgpcustomizemenubutton.cpp

📁 关于远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{
		BOOL bImageSave = m_bImage;
		BOOL bUserButton = m_bUserButton;
		BOOL bSuccess = TRUE;
		
		m_bImage = TRUE;	// Always try to draw image!
		m_bUserButton = TRUE;
		
		if (GetImage () < 0)
		{
			m_bUserButton = FALSE;
			
			if (GetImage () < 0)
			{
				bSuccess = FALSE;
			}
		}
		
		if (!bSuccess)
		{
			m_bImage = bImageSave;
			m_bUserButton = bUserButton;
		}
	}
		
	if(m_uiIndex == ID_BCGBARRES_TOOLBAR_RESET_PROMT)
	{
		m_bImage = FALSE;
	}
	
	BOOL bImageIsReady = FALSE;
	
	CRgn rgnClip;
	rgnClip.CreateRectRgnIndirect (&rectImage);
	
	if(m_iImage != -1)
	{
		FillInterior (pDC, rectFrameBtn, bHighlight);
	}
	
	if (!bDisableImage && IsDrawImage () && pImages != NULL)
	{
		BOOL bDrawImageShadow = 
			bHighlight && !bCustomizeMode &&
			CBCGPVisualManager::GetInstance ()->IsShadowHighlightedImage () &&
			((m_nStyle & TBBS_CHECKED) == 0) &&
			((m_nStyle & TBBS_DISABLED) == 0);
		
		pDC->SelectObject (&rgnClip);
		
		CPoint ptImageOffset (
			(rectImage.Width () - CBCGPToolBar::GetMenuImageSize ().cx) / 2, 
			(rectImage.Height () - CBCGPToolBar::GetMenuImageSize ().cy) / 2);
		
		if ((m_nStyle & TBBS_CHECKED) && !bCustomizeMode &&
			!CBCGPVisualManager::GetInstance ()->IsShadowHighlightedImage ())
		{
			ptImageOffset.x ++;
			ptImageOffset.y ++;
			
		}
		
		if ((m_nStyle & TBBS_PRESSED) || 
			!(m_nStyle & TBBS_DISABLED) ||
			!bGrayDisabledButtons ||
			bCustomizeMode)
		{
			if (pUserTool != NULL)
			{
				pUserTool->DrawToolIcon (pDC, 
					CRect (CPoint (rectImage.left + ptImageOffset.x, 
					rectImage.top + ptImageOffset.y),
					CBCGPToolBar::GetMenuImageSize ()));
			}
			else
			{
				CPoint pt = rectImage.TopLeft ();
				pt += ptImageOffset;
				
				if (bDrawImageShadow)
				{
					pImages->Draw (pDC, 
						pt.x,
						pt.y, 
						GetImage (), FALSE, FALSE, FALSE, TRUE);
					
					pt.Offset (-1, -1);
				}
				
				pImages->Draw (pDC, 
					pt.x, 
					pt.y, 
					GetImage ());
			}
			
			if (bCustomizeMode || m_nStyle & TBBS_PRESSED)
			{
				bImageIsReady = TRUE;
			}
		}
		
		if (!bImageIsReady)
		{
			if (pUserTool != NULL)
			{
				pUserTool->DrawToolIcon (pDC, 
					CRect (CPoint (rectImage.left + ptImageOffset.x, 
					rectImage.top + ptImageOffset.y),
					CBCGPToolBar::GetMenuImageSize ()));
			}
			else
			{
				if (bDrawImageShadow)
				{
					pImages->Draw (pDC, 
						rectImage.left + ptImageOffset.x,
						rectImage.top + ptImageOffset.y,
						GetImage (), FALSE, FALSE, FALSE, TRUE);
					
					rectImage.OffsetRect (-1, -1);
				}
				
				pImages->Draw (pDC, 
					rectImage.left + ptImageOffset.x, rectImage.top + ptImageOffset.y, 
					GetImage (), FALSE, bDisabled && bGrayDisabledButtons,
					FALSE, FALSE, bFadeImage);
			}
			
			bImageIsReady = TRUE;
		}
	}
	
	/*	
	if (m_bAlwaysCallOwnerDraw || !bImageIsReady)
	{
	CFrameWnd* pParentFrame = m_pWndParent == NULL ?
	DYNAMIC_DOWNCAST (CFrameWnd, AfxGetMainWnd ()) :
	BCGCBProGetTopLevelFrame (m_pWndParent);
	
	  //------------------------------------
	  // Get chance to user draw menu image:
	  //------------------------------------
	  CBCGPMDIFrameWnd* pMainFrame = DYNAMIC_DOWNCAST (CBCGPMDIFrameWnd, pParentFrame);
	  if (pMainFrame != NULL)
	  {
	  bImageIsReady = pMainFrame->OnDrawMenuImage (pDC, this, rectImage);
	  }
	  else	// Maybe, SDI frame...
	  {
	  CBCGPFrameWnd* pFrame = DYNAMIC_DOWNCAST (CBCGPFrameWnd, pParentFrame);
	  if (pFrame != NULL)
	  {
	  bImageIsReady = pFrame->OnDrawMenuImage (pDC, this, rectImage);
	  }
	  else	// Maybe, OLE frame...
	  {
	  CBCGPOleIPFrameWnd* pOleFrame = 
	  DYNAMIC_DOWNCAST (CBCGPOleIPFrameWnd, pParentFrame);
	  if (pOleFrame != NULL)
	  {
	  bImageIsReady = pOleFrame->OnDrawMenuImage (pDC, this, rectImage);
	  }
	  else
	  {
	  CBCGPOleDocIPFrameWnd* pOleDocFrame = 
						DYNAMIC_DOWNCAST (CBCGPOleDocIPFrameWnd, pParentFrame);
						if (pOleDocFrame != NULL)
						{
						bImageIsReady = pOleDocFrame->OnDrawMenuImage (pDC, this, rectImage);
						}
						}
						
						  }
						  }
						  }
						  */
						  
						  pDC->SelectClipRgn (NULL);
						  
						  rectImage.right ++;
						  
						  /*
						  if (m_nStyle & TBBS_CHECKED && !bImageIsReady)
						  {
						  CRect rectCheck = rectImage;
						  rectCheck.DeflateRect (0, 1);
						  
							if (!bLightImage && bIsRarelyUsed)
							{
							pDC->FillRect (rectCheck, &globalData.brBtnFace);
							}
							
							  CPoint pointCheck (
							  rectCheck.left + (rectCheck.Width () - sizeImage.cx) / 2,
							  rectCheck.top + (rectCheck.Height () - sizeImage.cy) / 2);
							  
								int iImage = m_bIsRadio ? CMenuImages::IdRadio : CMenuImages::IdCheck;
								
								  FillInterior (pDC, rectCheck, bHighlight);
								  CMenuImages::Draw (pDC, (CMenuImages::IMAGES_IDS) iImage, 
								  pointCheck,
								  (m_nStyle & TBBS_DISABLED) ? CMenuImages::ImageGray : CMenuImages::ImageBlack);
								  
									CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
									this, rectFrameBtn, CBCGPVisualManager::ButtonsIsPressed);
									}
									else if (bImageIsReady && bHighlight && !(m_nStyle & TBBS_CHECKED))
									{
									CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
									this, rectFrameBtn, CBCGPVisualManager::ButtonsIsHighlighted);
									}
									else if (bImageIsReady && (m_nStyle & TBBS_CHECKED))
									{
									CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
									this, rectFrameBtn, CBCGPVisualManager::ButtonsIsPressed);
									}
						  */
						  
						  int iSystemImageId = -1;
						  /*
						  //-------------------------------
						  // Try to draw system menu icons:
						  //-------------------------------
						  if (!bImageIsReady)
						  {
						  switch (m_nID)
						  {
						  case SC_MINIMIZE:
						  iSystemImageId = CMenuImages::IdMinimize;
						  break;
						  
							case SC_RESTORE:
							iSystemImageId = CMenuImages::IdRestore;
							break;
							
							  case SC_CLOSE:
							  iSystemImageId = CMenuImages::IdClose;
							  break;
							  
								case SC_MAXIMIZE:
								iSystemImageId = CMenuImages::IdMaximize;
								break;
								}
								
								  if (iSystemImageId != -1)
								  {
								  CRect rectSysImage = rectImage;
								  rectSysImage.DeflateRect (CBCGPVisualManager::GetInstance ()->GetMenuImageMargin (), CBCGPVisualManager::GetInstance ()->GetMenuImageMargin ());
								  
									
									  CPoint pointSysImage (
									  rectSysImage.left + (rectSysImage.Width () - sizeImage.cx) / 2,
									  rectSysImage.top + (rectSysImage.Height () - sizeImage.cy) / 2);
									  
										FillInterior (pDC, rectFrameBtn, bHighlight);
										CMenuImages::Draw (pDC, (CMenuImages::IMAGES_IDS) iSystemImageId, pointSysImage,
										bDisabled ? CMenuImages::ImageGray : CMenuImages::ImageBlack);
										
										  if (bHighlight)
										  {
										  CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
										  this, rectFrameBtn, CBCGPVisualManager::ButtonsIsHighlighted);
										  }
										  }
										  }
						  */
						  
						  //-------------------------------
						  // Fill text area if highlighted:
						  //-------------------------------
						  CRect rectText = rect;
						  rectText.left = rectFrameBtn.right + CBCGPVisualManager::GetInstance ()->GetMenuImageMargin () + 2;
						  
						  
						  COLORREF clrText;
						  
						  if (bHighlight)
						  {
							  CRect rectFill = rectFrameBtn;
							  
							  if ((m_nStyle & (TBBS_CHECKED) || bImageIsReady) ||
								  iSystemImageId != -1)
							  {
								  rectFill.left = rectText.left - 1;
							  }
							  
							  rectFill.right = rect.right - 1;
							  
							 
							  CRuntimeClass* pRTC = CBCGPVisualManager::GetInstance ()->GetRuntimeClass();

							  if(!pRTC->IsDerivedFrom(RUNTIME_CLASS(CBCGPVisualManagerXP)))
							  {
								  clrText = globalData.clrTextHilite;					
	
							  }else
							  { 
								  clrText = globalData.clrBtnText;	 
							  }
							 
						  }
						  else
						  {
							  clrText	= bDisabled ?
								  globalData.clrGrayedText : 
							  globalData.clrBtnText;
						  }
						  
						  //-------------------------
						  // Find acceleration label:
						  //-------------------------
						  CString strText = m_strText;
						  CString strAccel;
						  
						  int iTabOffset = m_strText.Find (_T('\t'));
						  if (iTabOffset >= 0)
						  {
							  strText = strText.Left (iTabOffset);
							  strAccel = m_strText.Mid (iTabOffset + 1);
						  }
						  
						  //-----------
						  // Draw text:
						  //-----------
						  COLORREF clrTextOld = pDC->GetTextColor ();
						  
						  rectText.left += TEXT_MARGIN;
						  
						  if (!m_bWholeText)
						  {
							  CString strEllipses (_T("..."));
							  while (strText.GetLength () > 0 &&
								  pDC->GetTextExtent (strText + strEllipses).cx > rectText.Width ())
							  {
								  strText = strText.Left (strText.GetLength () - 1);
							  }
							  
							  strText += strEllipses;
						  }
						  
						  if (bDisabled && !bHighlight)
						  {
							  pDC->SetTextColor (globalData.clrBtnHilite);
							  
							  CRect rectShft = rectText;
							  rectShft.OffsetRect (1, 1);
							  pDC->DrawText (strText, &rectShft, DT_SINGLELINE | DT_VCENTER);
						  }
						  
						  pDC->SetTextColor (clrText);
						  pDC->DrawText (strText, &rectText, DT_SINGLELINE | DT_VCENTER);
						  
						  //------------------------
						  // Draw accelerator label:
						  //------------------------
						  if (!strAccel.IsEmpty ())
						  {
							  CRect rectAccel = rectText;
							  rectAccel.right -= TEXT_MARGIN + sizeImage.cx;
							  
							  if (bDisabled && !bHighlight)
							  {
								  pDC->SetTextColor (globalData.clrBtnHilite);
								  
								  CRect rectAccelShft = rectAccel;
								  rectAccelShft.OffsetRect (1, 1);
								  pDC->DrawText (strAccel, &rectAccelShft, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
							  }
							  
							  pDC->SetTextColor (clrText);
							  pDC->DrawText (strAccel, &rectAccel, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
						  }
						  
						  //--------------------------------------------
						  // Draw triangle image for the cascade menues:
						  //--------------------------------------------
						  if (m_nID == (UINT) -1 || m_bDrawDownArrow || m_bMenuOnly)
						  {
							  CFont* pRegFont = pDC->SelectObject (&globalData.fontMarlett);
							  ASSERT (pRegFont != NULL);
							  
							  CRect rectTriangle = rect;
							  
							  //const CString strTriangle (_T("6"));	// Marlett's right arrow
							  
							  CString strTriangle (_T("4")); 	// Marlett's right arrow
							  if(TRUE == m_bQuickCustomMode)
							  {
								  
								  strTriangle = _T("6");  	// Marlett's down arrow
							  }
							  
							  pDC->DrawText (strTriangle, &rectTriangle, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
							  
							  pDC->SelectObject (pRegFont);
						  }
						  
						  if (pOldFont != NULL)
						  {
							  pDC->SelectObject (pOldFont);
						  }
						  
						  pDC->SetTextColor (clrTextOld);
}
//****************************************************************************************
CString CBCGPCustomizeMenuButton::SearchCommandText(CMenu* pMenu, UINT in_uiCmd)
{
	ASSERT (pMenu != NULL);
	
	int iCount = (int) pMenu->GetMenuItemCount ();
	
	for (int i = 0; i < iCount; i ++)
	{
		UINT uiCmd = pMenu->GetMenuItemID (i);
		if (uiCmd == in_uiCmd)
		{
			CString strText;
			pMenu->GetMenuString (i, strText, MF_BYPOSITION);
			return strText;
		}
		
		switch (uiCmd)
		{
		case 0:		// Separator, ignore it.
			break;
			
		case -1:	// Submenu
			{
				CMenu* pSubMenu = pMenu->GetSubMenu (i);
				
				CString strText = SearchCommandText (pSubMenu, in_uiCmd);
				if(strText != _T("")) return strText;
			}
			break;
			
		}//end switch
	}//end for
	
	return _T("");
}
//****************************************************************************************
void CBCGPCustomizeMenuButton::DrawCheckBox(CDC* pDC, const CRect& rect, BOOL bHighlight)
{	
	CRect rectFrameBtn = rect;
	if (m_bShow && (!(m_nStyle & TBBS_DISABLED)))  
	{
		CRect rectCheck = rect;
		rectCheck.DeflateRect (1, 1);
				
		CPoint pointCheck (
			rect.left + ((rect.Width () / 2)-5),
			rect.top + ((rect.Height () / 2)-5));
		
		int iImage = CMenuImages::IdCheck;
		
		UINT nStyle = m_nStyle;
		m_nStyle |= TBBS_CHECKED;
		
		FillInterior (pDC, rectCheck, bHighlight);
		
		m_nStyle = nStyle;
		
		CMenuImages::Draw (pDC, (CMenuImages::IMAGES_IDS) iImage, 
			pointCheck,
			(m_nStyle & TBBS_DISABLED) ? CMenuImages::ImageGray : CMenuImages::ImageBlack);
		
		
		CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
			this, rectFrameBtn, CBCGPVisualManager::ButtonsIsPressed);
	}
	else if (m_bShow && (m_nStyle & TBBS_DISABLED)) 
	{
		CRect rectCheck = rect;
		rectCheck.DeflateRect (0, 1);
		
		FillInterior (pDC, rectCheck, TRUE);
		
		CPoint pointCheck (
			rectCheck.left + (rectCheck.Width () )/ 4,
			rectCheck.top + (rectCheck.Height () )/ 4);
		
		int iImage = CMenuImages::IdCheck;
		CMenuImages::Draw (pDC, (CMenuImages::IMAGES_IDS) iImage, 
			pointCheck, CMenuImages::ImageGray );
		
		CRect rcFrame = rectFrameBtn;
		rcFrame.DeflateRect(0,0,1,1);
		
		CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
			this, rectFrameBtn, CBCGPVisualManager::ButtonsIsPressed);	
	}	
	else if (bHighlight && !(m_nStyle & TBBS_CHECKED))
	{
		//CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
		//	this, rectFrameBtn, CBCGPVisualManager::ButtonsIsHighlighted);
	}
	else if ((m_nStyle & TBBS_CHECKED))
	{
		CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
			this, rectFrameBtn, CBCGPVisualManager::ButtonsIsPressed);
	}
}
//****************************************************************************************
void CBCGPCustomizeMenuButton::UpdateCustomizeButton()
{
	CCustomizeButton* pCustomizeBtn = m_pWndToolBar->GetCustomizeButton ();
	if ((pCustomizeBtn != NULL) &&  (pCustomizeBtn->GetExtraSize () != CSize (0, 0)))
	{
		CRect rect = pCustomizeBtn->GetInvalidateRect ();
		rect.InflateRect (10, 10);
		m_pWndToolBar->InvalidateRect (rect);
		rect.InflateRect (pCustomizeBtn->GetExtraSize ());
		m_pWndToolBar->RedrawWindow (rect, NULL, RDW_FRAME | RDW_INVALIDATE);
	}	
}
//****************************************************************************************
BOOL CBCGPCustomizeMenuButton::IsCommandExist(UINT uiCmdId)
{
	int nTmp = 0;
	return m_mapPresentIDs.Lookup(uiCmdId, nTmp);
}

⌨️ 快捷键说明

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