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

📄 bcgpdropdown.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			CBCGPToolbarButton::OnDraw (pDC, rectParent, 
									&m_pToolBar->m_ImagesLocked, bHorz, bCustomizeMode, bHighlight, 
									FALSE, bGrayDisabledButtons);
		}
		m_bDisableFill = bDisableFill;
		m_iImage = -1;
		m_iUserImage = -1;
		m_bImage = bImage;
		
		if (!m_bLocalUserButton)
		{
			m_pToolBar->m_ImagesLocked.EndDrawImage (ds);
		}
		else
		{
			m_pToolBar->m_pUserImages->EndDrawImage (ds);
		}
		m_bInternalDraw = FALSE;

	
	}

	int offset = (m_nStyle & TBBS_PRESSED) ? 1 : 0;
	
	CPoint triang [] = 
	{
		CPoint( rect.right - nActualArrowSize + offset - 1, rect.bottom - nHalfArrowSize + offset + 1),
		CPoint (rect.right - nHalfArrowSize + offset + 1, rect.bottom - nHalfArrowSize + offset + 1),
		CPoint (rect.right - nHalfArrowSize + offset + 1, rect.bottom - nActualArrowSize + offset - 1)
	};
	
	CPen* pOldPen = (CPen*) pDC->SelectStockObject (NULL_PEN);
	ASSERT (pOldPen != NULL);

	CBrush* pOldBrush = (CBrush*) pDC->SelectObject (&globalData.brBlack);
	ASSERT (pOldBrush != NULL);

	pDC->Polygon (triang, 3);

	if (!bCustomizeMode && HaveHotBorder () && bDrawBorder)
	{
		if (m_pPopupMenu != NULL ||
			(m_nStyle & (TBBS_PRESSED | TBBS_CHECKED)))
		{
			//-----------------------
			// Pressed in or checked:
			//-----------------------
			if (m_nID != 0 && m_nID != (UINT) -1)
			{
				CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
					this, rect, CBCGPVisualManager::ButtonsIsPressed);
			}
			else
			{
				CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
					this, rect, CBCGPVisualManager::ButtonsIsHighlighted);
			}
		}
		else if (bHighlight && !(m_nStyle & TBBS_DISABLED) &&
			!(m_nStyle & (TBBS_CHECKED | TBBS_INDETERMINATE)))
		{
			if (m_nStyle & TBBS_PRESSED)
			{
				CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
					this, rect, CBCGPVisualManager::ButtonsIsPressed);
			}
			else
			{
				CBCGPVisualManager::GetInstance ()->OnDrawButtonBorder (pDC,
					this, rect, CBCGPVisualManager::ButtonsIsHighlighted);
				
			}
		}
	}
	
	pDC->SelectObject (pOldPen);
	pDC->SelectObject (pOldBrush);
}

static CBCGPDropDownToolbarButton* g_pButtonDown = NULL;

static void CALLBACK EXPORT TimerProc(HWND hWnd, UINT, UINT, DWORD)
{
	CWnd* pwnd = CWnd::FromHandle (hWnd);
	if (g_pButtonDown != NULL)
	{
		g_pButtonDown->OnClick (pwnd, FALSE);
	}
}
//*****************************************************************************************
BOOL CBCGPDropDownToolbarButton::OnClick (CWnd* pWnd, BOOL bDelay)
{
	ASSERT_VALID (pWnd);
	if (m_uiTimer == 0)
	{
		if (m_pWndParent != NULL)
		{
			m_uiTimer = m_pWndParent->SetTimer (uiShowBarTimerId, uiShowBarDelay, TimerProc);
		}

		g_pButtonDown = this;
		return CBCGPToolbarButton::OnClick (pWnd, bDelay);
	}
	
	if (m_pWndParent != NULL)
	{
		m_pWndParent->KillTimer (m_uiTimer);
	}

	m_uiTimer = 0;
	g_pButtonDown = NULL;
	
	CBCGPMenuBar* pMenuBar = DYNAMIC_DOWNCAST (CBCGPMenuBar, m_pWndParent);
	
	if (m_pPopupMenu != NULL)
	{
		//-----------------------------------------------------
		// Second click to the popup menu item closes the menu:
		//-----------------------------------------------------		
		ASSERT_VALID(m_pPopupMenu);
		
		m_pPopupMenu->m_bAutoDestroyParent = FALSE;
		m_pPopupMenu->DestroyWindow ();
		m_pPopupMenu = NULL;
		
		if (pMenuBar != NULL)
		{
			pMenuBar->SetHot (NULL);
		}
	}
	else
	{
		CBCGPPopupMenuBar* pParentMenu =
			DYNAMIC_DOWNCAST (CBCGPPopupMenuBar, m_pWndParent);
		if (bDelay && pParentMenu != NULL && !CBCGPToolBar::IsCustomizeMode ())
		{
		}
		else
		{
			DropDownToolbar(pWnd);
		}
		
		if (pMenuBar != NULL)
		{
			pMenuBar->SetHot (this);
		}
	}
	
	if (m_pWndParent != NULL)
	{
		m_pWndParent->InvalidateRect (m_rect);
	}
	
	return FALSE;
}
//****************************************************************************************
BOOL CBCGPDropDownToolbarButton::OnClickUp()
{
	CBCGPMenuBar* pMenuBar = DYNAMIC_DOWNCAST (CBCGPMenuBar, m_pWndParent);
	
	if (m_uiTimer)
	{
		if (m_pWndParent != NULL)
		{
			m_pWndParent->KillTimer (m_uiTimer);
		}

		m_uiTimer = 0;
		g_pButtonDown = NULL;
		return FALSE;
	}
	
	if (m_pPopupMenu != NULL)
	{
		//-----------------------------------------------------
		// Second click to the popup menu item closes the menu:
		//-----------------------------------------------------		
		ASSERT_VALID(m_pPopupMenu);
		
		m_pPopupMenu->m_bAutoDestroyParent = FALSE;
		m_pPopupMenu->DestroyWindow ();
		m_pPopupMenu = NULL;
		
		if (pMenuBar != NULL)
		{
			pMenuBar->SetHot (NULL);
		}
	}
	
	return TRUE;
}
//****************************************************************************************
void CBCGPDropDownToolbarButton::OnChangeParentWnd (CWnd* pWndParent)
{
	CBCGPToolbarButton::OnChangeParentWnd (pWndParent);

	m_pWndParent = pWndParent;
	m_bText = FALSE;
	m_strText.Empty ();
	m_bUserButton = FALSE;
}
//****************************************************************************************
void CBCGPDropDownToolbarButton::OnCancelMode ()
{
	if (m_pWndParent != NULL && ::IsWindow (m_pWndParent->m_hWnd))
	{
		m_pWndParent->InvalidateRect (m_rect);
		m_pWndParent->UpdateWindow ();
	}
}

/////////////////////////////////////////////////////////////////////////////
// CBCGPDropDownToolbarButton diagnostics

#ifdef _DEBUG
void CBCGPDropDownToolbarButton::AssertValid() const
{
	CObject::AssertValid();
}

//******************************************************************************************
void CBCGPDropDownToolbarButton::Dump(CDumpContext& dc) const
{
	CObject::Dump (dc);
}

#endif

//****************************************************************************************
BOOL CBCGPDropDownToolbarButton::DropDownToolbar (CWnd* pWnd)
{
	if (m_pToolBar == NULL)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	if (m_pPopupMenu != NULL)
	{
		return FALSE;
	}
	
	if (pWnd == NULL)
	{
		pWnd = m_pWndParent;
		if (m_pWndParent == NULL)
		{
			return FALSE;
		}
	}
	
	//---------------------------------------------------------------
	// Define a new menu position. Place the menu in the right side
	// of the current menu in the poup menu case or under the current 
	// item by default:
	//---------------------------------------------------------------
	CPoint point;
	
	CBCGPToolBar* pParentBar =
		DYNAMIC_DOWNCAST (CBCGPToolBar, m_pWndParent);
	
	if (pParentBar != NULL && !pParentBar->IsHorizontal ())
	{
		//------------------------------------------------
		// Parent menu bar is docked vertical, place menu 
		// in the left or right side of the parent frame:
		//------------------------------------------------
		point = CPoint (m_rect.right + 1, m_rect.top);
		pWnd->ClientToScreen (&point);
	}
	else
	{
		point = CPoint (m_rect.left - 1, m_rect.bottom);
		pWnd->ClientToScreen (&point);
	}
	
	m_pPopupMenu = new CBCGPDropDownFrame;
	m_pPopupMenu->m_pParentBtn = this;
	
	return m_pPopupMenu->Create (pWnd, point.x, point.y, m_pToolBar);
}
//*********************************************************************************
SIZE CBCGPDropDownToolbarButton::OnCalculateSize (CDC* pDC, const CSize& sizeDefault, BOOL bHorz)
{
	if (m_nID == 0 && m_pToolBar != NULL)
	{
		ASSERT_VALID (m_pToolBar);

		CBCGPToolbarButton* pButton = m_pToolBar->GetButton (0);
		if (pButton == NULL)	// Toolbar is empty!
		{
			ASSERT (FALSE);
		}
		else
		{
			SetDefaultCommand (pButton->m_nID);
		}
	}

	BOOL bImage = m_bImage;

	m_iImage = m_iSelectedImage;
	m_bImage = TRUE;

	CSize sizeBtn = CBCGPToolbarButton::OnCalculateSize (pDC, sizeDefault, bHorz);

	m_iImage = -1;
	m_bImage = bImage;

	int nArrowWidth = CBCGPToolBar::IsLargeIcons () ? nArrowSize + 2 : nArrowSize / 2 + 1;
	sizeBtn.cx += nArrowWidth;

	return sizeBtn;
}
//*************************************************************************************
BOOL CBCGPDropDownToolbarButton::ExportToMenuButton (CBCGPToolbarMenuButton& menuButton) const
{
	if (m_pToolBar == NULL)
	{
		ASSERT (FALSE);
		return FALSE;
	}

	if (!CBCGPToolbarButton::ExportToMenuButton (menuButton))
	{
		return FALSE;
	}

	//------------------------------------
	// Create a popup menu with all items:
	//------------------------------------
	CMenu menu;
	menu.CreatePopupMenu ();

	for (POSITION pos = m_pToolBar->m_Buttons.GetHeadPosition (); pos != NULL;)
	{
		CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) m_pToolBar->m_Buttons.GetNext (pos);
		ASSERT (pButton != NULL);

		if (pButton->m_nStyle & TBBS_SEPARATOR)
		{
			menu.AppendMenu (MF_SEPARATOR);
		}
		else if (pButton->m_nID != 0 && pButton->m_nID != (UINT) -1)// Ignore sub-menus
		{
			CString strItem = pButton->m_strText;
			if (strItem.IsEmpty ())
			{
				CString strMessage;
				int iOffset;

				if (strMessage.LoadString (pButton->m_nID) &&
					(iOffset = strMessage.Find (_T('\n'))) != -1)
				{
					strItem = strMessage.Mid (iOffset + 1);
				}
			}

			menu.AppendMenu (MF_STRING, pButton->m_nID, strItem);
		}
	}

	menuButton.m_nID = 0;
	menuButton.m_strText = m_strName;
	menuButton.SetImage (-1);
	menuButton.m_bImage = FALSE;
	menuButton.CreateFromMenu (menu);

	menu.DestroyMenu ();
	return TRUE;
}
//*************************************************************************************
int CBCGPDropDownToolbarButton::OnDrawOnCustomizeList (CDC* pDC, const CRect& rect, 
										BOOL bSelected)
{
	CString strText = m_strText;
	m_strText = m_strName;

	int iResult = CBCGPToolbarButton::OnDrawOnCustomizeList (
					pDC, rect, bSelected);

	m_strText = strText;
	return iResult;
}
//*********************************************************************************
BOOL CBCGPDropDownToolbarButton::OnCustomizeMenu (CMenu* pPopup)
{
	ASSERT_VALID (this);
	ASSERT_VALID (pPopup);

	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_COPY_IMAGE, MF_GRAYED | MF_BYCOMMAND);

	return TRUE;
}

⌨️ 快捷键说明

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