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

📄 bcgppopupmenubar.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
{
	if (m_bFirstMove)
	{
		m_bFirstMove = FALSE;
		return;
	}

	CRect rectClient;
	GetClientRect (&rectClient);

	if (IsCustomizeMode () ||
		rectClient.PtInRect (point))
	{
		CBCGPToolBar::OnMouseMove(nFlags, point);
	}
	else
	{
		CBCGPToolBar* pDestBar = FindDestBar (point);
		if (pDestBar != NULL)
		{
			MapWindowPoints (pDestBar, &point, 1);
			pDestBar->SendMessage (	WM_MOUSEMOVE, 
									nFlags, 
									MAKELPARAM (point.x, point.y));
		}
	}
}
//***************************************************************************************
CBCGPToolBar* CBCGPPopupMenuBar::FindDestBar (CPoint point)
{
	ScreenToClient (&point);

	CRect rectClient;

	CBCGPPopupMenu* pPopupMenu = DYNAMIC_DOWNCAST (CBCGPPopupMenu, GetParent ());
	if (pPopupMenu == NULL)
	{
		return NULL;
	}

	ASSERT_VALID (pPopupMenu);

	CBCGPPopupMenu* pLastPopupMenu = pPopupMenu;

	//-------------------------------
	// Go up trougth all popup menus:
	//-------------------------------
	while ((pPopupMenu = pPopupMenu->GetParentPopupMenu ()) != NULL)
	{
		CBCGPPopupMenuBar* pPopupMenuBar = pPopupMenu->GetMenuBar ();
		ASSERT_VALID (pPopupMenuBar);

		pPopupMenuBar->GetClientRect (&rectClient);
		pPopupMenuBar->MapWindowPoints (this, &rectClient);

		if (rectClient.PtInRect (point))
		{
			return pPopupMenuBar;
		}

		pLastPopupMenu = pPopupMenu;
	}

	ASSERT_VALID (pLastPopupMenu);

	//--------------------
	// Try parent toolbar:
	//--------------------
	CBCGPToolBar* pToolBar = pLastPopupMenu->GetParentToolBar ();
	if (pToolBar != NULL)
	{
		pToolBar->GetClientRect (&rectClient);
		pToolBar->MapWindowPoints (this, &rectClient);

		if (rectClient.PtInRect (point))
		{
			return pToolBar;
		}
	}

	return NULL;
}
//*********************************************************************************************
DROPEFFECT CBCGPPopupMenuBar::OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
	//-----------------------------------------------
	// Disable MOVING menu item into one of submenus!
	//-----------------------------------------------
	if ((dwKeyState & MK_CONTROL) == 0)
	{
		CBCGPPopupMenu* pParentMenu = DYNAMIC_DOWNCAST (CBCGPPopupMenu, GetParent ());
		if (pParentMenu != NULL)
		{
			CBCGPToolBar* pParentBar = pParentMenu->GetParentToolBar ();
			CBCGPToolbarMenuButton* pParentButton = pParentMenu->GetParentButton ();

			if (pParentBar != NULL && pParentButton != NULL &&
				pParentBar->IsDragButton (pParentButton))
			{
				return DROPEFFECT_NONE;
			}
		}
	}

	return CBCGPToolBar::OnDragOver(pDataObject, dwKeyState, point);
}
//*****************************************************************************************
void CBCGPPopupMenuBar::OnFillBackground (CDC* pDC)
{
	ASSERT_VALID (this);
	ASSERT (::IsWindow (GetSafeHwnd ()));
	ASSERT_VALID (pDC);

	if (CBCGPToolBar::IsCustomizeMode () ||
		!CBCGPMenuBar::m_bRecentlyUsedMenus ||
		m_bPaletteMode)
	{
		return;
	}

	//--------------------------------------------------------------
	// Only menubar first-level menus may hide rarely used commands:
	//--------------------------------------------------------------
	CBCGPPopupMenu* pParentMenu = DYNAMIC_DOWNCAST (CBCGPPopupMenu, GetParent ());
	if (pParentMenu == NULL || !pParentMenu->HideRarelyUsedCommands ())
	{
		return;
	}

	BOOL bFirstRarelyUsedButton = TRUE;
	CRect rectRarelyUsed;

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

		if (pButton->m_nStyle & TBBS_SEPARATOR)
		{
			if (pos != NULL &&
				CBCGPToolBar::IsCommandRarelyUsed (
					((CBCGPToolbarButton*) m_Buttons.GetAt (pos))->m_nID))
			{
				continue;
			}
		}

		BOOL bDraw = FALSE;

		if (CBCGPToolBar::IsCommandRarelyUsed (pButton->m_nID))
		{
			if (bFirstRarelyUsedButton)
			{
				bFirstRarelyUsedButton = FALSE;
				rectRarelyUsed = pButton->Rect ();
			}

			if (pos == NULL)	// Last button
			{
				rectRarelyUsed.bottom = pButton->Rect ().bottom;
				bDraw = TRUE;
			}
		}
		else
		{
			if (!bFirstRarelyUsedButton)
			{
				rectRarelyUsed.bottom = pButton->Rect ().top;
				bDraw = TRUE;
			}

			bFirstRarelyUsedButton = TRUE;
		}

		if (bDraw)
		{
			CBCGPVisualManager::GetInstance ()->OnHighlightRarelyUsedMenuItems (
				pDC, rectRarelyUsed);
		}
	}
}
//*************************************************************************************
int CBCGPPopupMenuBar::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
{
	ASSERT_VALID(this);

	if (m_bPaletteMode)
	{
		return CBCGPToolBar::OnToolHitTest (point, pTI);
	}

	int nHit = ((CBCGPPopupMenuBar*)this)->HitTest(point);
	if (nHit != -1)
	{
		CBCGPToolbarButton* pButton = 
			DYNAMIC_DOWNCAST (CBCGPToolbarButton, GetButton (nHit));

		if (pButton != NULL)
		{
			if (pTI != NULL)
			{
				pTI->uId = pButton->m_nID;
				pTI->hwnd = GetSafeHwnd ();
				pTI->rect = pButton->Rect ();
			}

			if (!pButton->OnToolHitTest (this, pTI))
			{
				nHit = pButton->m_nID;
			}
		}
	}

	return nHit;
}
//**********************************************************************************
int CBCGPPopupMenuBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CBCGPToolBar::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (m_uiPopupTimerDelay == (UINT) -1)	// Not defined yet
	{
		m_uiPopupTimerDelay = 500;

		CBCGPRegistrySP regSP;
		CBCGPRegistry& reg = regSP.Create (FALSE, TRUE);

		if (reg.Open (_T("Control Panel\\Desktop")))
		{
			CString strVal;

			if (reg.Read (_T("MenuShowDelay"), strVal))
			{
				m_uiPopupTimerDelay = (UINT) _ttol (strVal);

				//------------------------
				// Just limit it to 5 sec:
				//------------------------
				m_uiPopupTimerDelay = min (5000, m_uiPopupTimerDelay);
			}
		}
	}
	
	return 0;
}
//*****************************************************************
void CBCGPPopupMenuBar::SetButtonStyle(int nIndex, UINT nStyle)
{
	CBCGPToolbarButton* pButton = GetButton (nIndex);
	if (pButton == NULL)
	{
		ASSERT (FALSE);
		return;
	}

	UINT nOldStyle = pButton->m_nStyle;
	if (nOldStyle != nStyle)
	{
		// update the style and invalidate
		pButton->m_nStyle = nStyle;

		// invalidate the button only if both styles not "pressed"
		if (!(nOldStyle & nStyle & TBBS_PRESSED))
		{
			CBCGPToolbarMenuButton* pMenuButton =
				DYNAMIC_DOWNCAST (CBCGPToolbarMenuButton, GetButton (nIndex));

			BOOL bWasChecked = nOldStyle & TBBS_CHECKED;
			BOOL bChecked = nStyle & TBBS_CHECKED;

			// If checked style was changed. redraw check box (or image) area only:
			if (pMenuButton != NULL && bWasChecked != bChecked)
			{
				CRect rectImage;
				pMenuButton->GetImageRect (rectImage);

				rectImage.InflateRect (afxData.cxBorder2 * 2, afxData.cyBorder2 * 2);

				InvalidateRect (rectImage);
				UpdateWindow ();
			}
			else if ((nOldStyle ^ nStyle) != TBSTATE_PRESSED)
			{
				InvalidateButton(nIndex);
			}
		}
	}
}
// ---------------------------------------------------------------
LRESULT CBCGPPopupMenuBar::OnIdleUpdateCmdUI(WPARAM wParam, LPARAM)
{
	if (m_bTrackMode)
	{
		return 0;
	}

	// the style must be visible and if it is docked
	// the dockbar style must also be visible
	if (GetStyle() & WS_VISIBLE)
	{
		CFrameWnd* pTarget = (CFrameWnd*) GetCommandTarget ();
		if (pTarget == NULL || !pTarget->IsFrameWnd())
		{
			pTarget = BCGPGetParentFrame(this);
		}

		if (pTarget != NULL)
		{
			BOOL bAutoMenuEnable = FALSE;
			if (pTarget->IsFrameWnd ())
			{
				bAutoMenuEnable = ((CFrameWnd*) pTarget)->m_bAutoMenuEnable;
			}

			OnUpdateCmdUI (pTarget, bAutoMenuEnable);
		}
	}

	return 0L;
}
// ---------------------------------------------------------------
CWnd* CBCGPPopupMenuBar::GetCommandTarget () const
{
	if (m_bTrackMode)
	{
		return NULL;
	}

	CBCGPPopupMenu* pParentMenu = DYNAMIC_DOWNCAST (CBCGPPopupMenu, GetParent ());
	if (pParentMenu != NULL && pParentMenu->GetMessageWnd () != NULL)
	{
         return pParentMenu;
	}

	return CBCGPToolBar::GetCommandTarget ();
}
//*******************************************************************************
void CBCGPPopupMenuBar::CloseDelayedSubMenu ()
{
	ASSERT_VALID (this);

	if (m_pDelayedClosePopupMenuButton != NULL)
	{
		ASSERT_VALID (m_pDelayedClosePopupMenuButton);

		KillTimer (uiRemovePopupTimerEvent);

		m_pDelayedClosePopupMenuButton->OnCancelMode ();
		m_pDelayedClosePopupMenuButton = NULL;
	}
}
//*******************************************************************************
void CBCGPPopupMenuBar::RestoreDelayedSubMenu ()
{
	ASSERT_VALID (this);

	if (m_pDelayedClosePopupMenuButton == NULL)
	{
		return;
	}

	ASSERT_VALID (m_pDelayedClosePopupMenuButton);
	m_pDelayedClosePopupMenuButton->m_bToBeClosed = FALSE;

	int iPrevHighlighted = m_iHighlighted;

	SetHot (m_pDelayedClosePopupMenuButton);

	m_iHighlighted = m_iHot;

	m_pDelayedClosePopupMenuButton = NULL;

	if (iPrevHighlighted != m_iHighlighted)
	{
		if (iPrevHighlighted >= 0)
		{
			InvalidateButton (iPrevHighlighted);
		}

		InvalidateButton (m_iHighlighted);
		UpdateWindow ();
	}

	KillTimer (uiRemovePopupTimerEvent);
}
//*******************************************************************************
BOOL CBCGPPopupMenuBar::LoadFromHash(HMENU hMenu)
{
	return g_menuHash.LoadMenuBar(hMenu, this);
}
//*******************************************************************************
void CBCGPPopupMenuBar::SetInCommand (BOOL bInCommand)
{
	ASSERT_VALID (this);

	m_bInCommand = bInCommand;

	CBCGPPopupMenu* pMenu = DYNAMIC_DOWNCAST (CBCGPPopupMenu, GetParent ());
	if (pMenu != NULL)
	{
		while ((pMenu = pMenu->GetParentPopupMenu ()) != NULL)
		{
			CBCGPPopupMenuBar* pMenuBar = pMenu->GetMenuBar ();
			if (pMenuBar != NULL)
			{
				pMenuBar->SetInCommand (bInCommand);
			}
		}
	}
}
//*******************************************************************************************
void CBCGPPopupMenuBar::OnToolbarImageAndText() 
{
	ASSERT (m_iSelected >= 0);

	CBCGPToolbarButton* pButton = GetButton(m_iSelected);
	if (pButton == NULL)
	{
		ASSERT (FALSE);
		return;
	}

	CMD_MGR.EnableMenuItemImage (pButton->m_nID, TRUE);
	AdjustLayout ();
}
//*************************************************************************************
void CBCGPPopupMenuBar::OnToolbarText() 
{
	ASSERT (m_iSelected >= 0);

	CBCGPToolbarButton* pButton = GetButton(m_iSelected);
	if (pButton == NULL)
	{
		ASSERT (FALSE);
		return;
	}

	CMD_MGR.EnableMenuItemImage (pButton->m_nID, FALSE);
	AdjustLayout ();
}
//************************************************************************************
void CBCGPPopupMenuBar::AdjustLayout ()
{
	ASSERT_VALID (this);

	if (GetSafeHwnd () == NULL)
	{
		return;
	}

	AdjustLocations ();

	Invalidate ();
	UpdateWindow ();

	if (!CBCGPToolBar::IsCustomizeMode ())
	{
		return;
	}

	CBCGPPopupMenu* pParentMenu = DYNAMIC_DOWNCAST (CBCGPPopupMenu, GetParent ());
	if (pParentMenu != NULL)
	{
		ASSERT_VALID (pParentMenu);
		pParentMenu->RecalcLayout (FALSE);
	}
}
//************************************************************************************
void CBCGPPopupMenuBar::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	int iItem = HitTest (point);

	if (iItem >= 0)
	{
		CBCGPToolbarMenuButton* pMenuItem = DYNAMIC_DOWNCAST (
			CBCGPToolbarMenuButton, GetButton (iItem));
		if (pMenuItem != NULL && pMenuItem->m_nID == (UINT) -1)
		{
			CWnd::OnLButtonDblClk(nFlags, point);
			return;
		}
	}

	CBCGPToolBar::OnLButtonDblClk(nFlags, point);
}
//************************************************************************************
void CBCGPPopupMenuBar::OnCalcSeparatorRect (CBCGPToolbarButton* pButton, 
											 CRect& rectSeparator, 
											 BOOL bHorz)
{
	CRect rectClient;
	GetClientRect (rectClient);
	
	rectSeparator = pButton->Rect ();

	if (pButton->m_bWrap && bHorz)
	{
		rectSeparator.right = rectClient.right;

		rectSeparator.top = pButton->Rect ().bottom;
		rectSeparator.bottom = rectSeparator.top + LINE_OFFSET;
	}	

}

⌨️ 快捷键说明

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