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

📄 bcgpmenubar.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:

	return CBCGPToolBar::OnSetDefaultButtonText (pButton);
}
//****************************************************************************************
BOOL CBCGPMenuBar::FindMenuItemText (HMENU hMenu, const UINT nItemID, CString& strOutText)
{
	if (hMenu == NULL || nItemID == 0 || nItemID == (UINT) -1)
	{
		return FALSE;
	}

	CMenu* pMenu = CMenu::FromHandle (hMenu);
	if (pMenu == NULL)
	{
		return FALSE;
	}

	int iCount = (int) pMenu->GetMenuItemCount ();
	for (int i = 0; i < iCount; i ++)
	{
		UINT uiID = pMenu->GetMenuItemID (i);
		if (uiID == nItemID)	// Found!
		{
			pMenu->GetMenuString (i, strOutText, MF_BYPOSITION);
			return TRUE;
		}
		else if (uiID == -1)	// Pop-up menu
		{
			CMenu* pPopupMenu = pMenu->GetSubMenu (i);
			ASSERT (pPopupMenu != NULL);

			if (FindMenuItemText (pPopupMenu->GetSafeHmenu (), nItemID, strOutText))
			{
				return TRUE;
			}
		}
	}

	return FALSE;
}
//****************************************************************************************
int CBCGPMenuBar::FindDropIndex (const CPoint point, CRect& rectDrag) const
{
	int iIndex = CBCGPToolBar::FindDropIndex (point, rectDrag);
	if (m_bMaximizeMode && iIndex >= 0)
	{
		//--------------------------------------
		// Maybe drag left from the system icon?
		//--------------------------------------
		if (iIndex == 0)
		{
			return -1;
		}

		//-----------------------------------------
		// Maybe drag right of the system buttons?
		//-----------------------------------------
		if (iIndex > GetCount () - m_nSystemButtonsNum)
		{
			iIndex = GetCount () - m_nSystemButtonsNum;

			if (m_nSystemButtonsNum > 0)
			{
				//----------------------------------------------------------
				// Put drag rectangle right of the last "non-system" button:
				//----------------------------------------------------------

				CBCGPToolbarButton* pLastButton = GetButton (iIndex - 1);
				ASSERT_VALID (pLastButton);

				CRect rectBtn = pLastButton->Rect ();
				CPoint ptDrag (rectBtn.right, rectBtn.top + rectBtn.Height () / 2);

				VERIFY (CBCGPToolBar::FindDropIndex (ptDrag, rectDrag) == iIndex);
			}
		}
	}

	return iIndex;
}
//****************************************************************************************
void CBCGPMenuBar::OnChangeHot (int iHot)
{
	CBCGPToolBar::OnChangeHot (iHot);

	KillTimer (uiShowAllItemsTimerId);

	if (GetDroppedDownMenu () == NULL)
	{
		m_bShowAllCommands = FALSE;
	}
	else
	{
		SetTimer (uiShowAllItemsTimerId, iShowAllItemsTimerFreq, NULL);
	}
}
//****************************************************************************************
void CBCGPMenuBar::SetShowAllCommands (BOOL bShowAllCommands)
{
	m_bShowAllCommands = bShowAllCommands;
}
//***************************************************************************************
void CBCGPMenuBar::SetRecentlyUsedMenus (BOOL bOn)
{
	m_bRecentlyUsedMenus = bOn;
}
//***************************************************************************************
CBCGPToolbarButton* CBCGPMenuBar::GetMenuItem (int iItem) const
{
	if (m_bMaximizeMode)
	{
		iItem --;	// Ignore system-menu button
	}

	return GetButton (iItem);
}
//***************************************************************************************
CBCGPToolbarSystemMenuButton* CBCGPMenuBar::GetSystemMenu () const
{
	if (!m_bMaximizeMode)
	{
		return NULL;
	}

	if (m_Buttons.IsEmpty ())
	{
		return NULL;
	}
	return DYNAMIC_DOWNCAST (CBCGPToolbarSystemMenuButton, m_Buttons.GetHead ());
}
//***************************************************************************************
CBCGPToolbarMenuButtonsButton* CBCGPMenuBar::GetSystemButton (UINT uiBtn, BOOL bByCommand) const
{
	if (!m_bMaximizeMode)
	{
		return NULL;
	}

	if (bByCommand)
	{
		for (POSITION pos = m_Buttons.GetTailPosition (); pos != NULL;)
		{
			CBCGPToolbarMenuButtonsButton* pButton = 
				DYNAMIC_DOWNCAST (CBCGPToolbarMenuButtonsButton,
									m_Buttons.GetPrev (pos));

			if (pButton == NULL)
			{
				break;
			}

			if (pButton->m_nID == uiBtn)
			{
				return pButton;
			}
		}

		return NULL;
	}
	// else - by index:
	if ((int) uiBtn < 0 || (int) uiBtn >= m_nSystemButtonsNum)
	{
		ASSERT (FALSE);
		return NULL;
	}

	int iIndex = m_Buttons.GetCount () - m_nSystemButtonsNum + uiBtn;

	CBCGPToolbarMenuButtonsButton* pButton = 
		DYNAMIC_DOWNCAST (CBCGPToolbarMenuButtonsButton, GetButton (iIndex));
	ASSERT_VALID (pButton);

	return pButton;
}
//************************************************************************************
BOOL CBCGPMenuBar::SetMenuFont (LPLOGFONT lpLogFont, BOOL bHorz)
{
	if (!globalData.SetMenuFont (lpLogFont, bHorz))
	{
		return FALSE;
	}
	
	//-------------------------------------------
	// Recalculate all toolbars and menus layout:
	//-------------------------------------------
	extern CObList gAllToolbars;

	for (POSITION pos = gAllToolbars.GetHeadPosition (); pos != NULL;)
	{
		CBCGPToolBar* pToolBar = (CBCGPToolBar*) gAllToolbars.GetNext (pos);
		ASSERT (pToolBar != NULL);

		if (CWnd::FromHandlePermanent (pToolBar->m_hWnd) != NULL)
		{
			ASSERT_VALID(pToolBar);
			pToolBar->AdjustLayout ();
		}
	}

	return TRUE;
}
//************************************************************************************
const CFont& CBCGPMenuBar::GetMenuFont (BOOL bHorz)
{
	return bHorz ? globalData.fontRegular : globalData.fontVert;
}
//************************************************************************************
void CBCGPMenuBar::OnTimer(UINT nIDEvent) 
{
	if (nIDEvent == uiShowAllItemsTimerId)
	{
		CPoint ptCursor;

		::GetCursorPos (&ptCursor);
		ScreenToClient (&ptCursor);

		//--------------------------------------------------------------
		// Check that the popup-menu is still exist and mouse cursor is
		// within the menu button:
		//--------------------------------------------------------------
		CBCGPToolbarMenuButton* pMenuButon = GetDroppedDownMenu ();
		if (pMenuButon != NULL && pMenuButon->m_pPopupMenu != NULL &&
			pMenuButon->m_rect.PtInRect (ptCursor) &&
			!pMenuButon->m_pPopupMenu->AreAllCommandsShown ())
		{
			pMenuButon->m_pPopupMenu->ShowAllCommands ();
		}

		KillTimer (uiShowAllItemsTimerId);
	}
	
	CBCGPToolBar::OnTimer(nIDEvent);
}
//*******************************************************************************************
void CBCGPMenuBar::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	int iButton = HitTest(point);
	BOOL bSysMenu = FALSE;

	if (iButton >= 0)
	{
		bSysMenu = 
			DYNAMIC_DOWNCAST (CBCGPToolbarSystemMenuButton, GetButton (iButton)) != NULL;
	}

	CBCGPToolBar::OnLButtonDblClk(nFlags, point);

	if (bSysMenu || IsShowAllCommands () || IsCustomizeMode ())
	{
		return;
	}

	if ((iButton = HitTest(point)) < 0)
	{
		return;
	}

	CBCGPToolbarMenuButton* pMenuButton = DYNAMIC_DOWNCAST (CBCGPToolbarMenuButton, GetButton(iButton));
	if (pMenuButton == NULL)
	{
		return;
	}

	//////////////////////////////////////////////
	// Special deal to system menu button 
	//--------------------------------------------
	if (pMenuButton->IsKindOf (RUNTIME_CLASS (CBCGPToolbarSystemMenuButton)))
	{
		return;
	}
	//--------------------------------------------
	//////////////////////////////////////////////

	m_bShowAllCommands = TRUE;
	pMenuButton->OnCancelMode ();

	if (!(pMenuButton->m_nStyle & TBBS_DISABLED) && 
		pMenuButton->OnClick (this, FALSE))
	{
		OnChangeHot (iButton);

		InvalidateButton (iButton);
		UpdateWindow(); // immediate feedback
	}
}
//***********************************************************************************
void CBCGPMenuBar::CalcSysButtonSize ()
{
	CWindowDC dc (NULL);

	CDC dcMem;
	dcMem.CreateCompatibleDC (NULL);	// Assume display!

	int iButtonWidth = ::GetSystemMetrics (SM_CXMENUSIZE);	
	int iButtonHeight = ::GetSystemMetrics (SM_CXMENUSIZE);

	CBitmap bmpMem;
	bmpMem.CreateCompatibleBitmap (&dc, iButtonWidth, iButtonHeight);

	CBitmap* pBmpOriginal = dcMem.SelectObject (&bmpMem);

	CRect rectBtn (0, 0, iButtonWidth, iButtonHeight);
	dcMem.DrawFrameControl (rectBtn, DFC_CAPTION, DFCS_ADJUSTRECT);

	m_szSystemButton = rectBtn.Size ();
	dcMem.SelectObject (pBmpOriginal);
}
//*********************************************************************************
void CBCGPMenuBar::OnSettingChange(UINT uFlags, LPCTSTR lpszSection) 
{
	CBCGPToolBar::OnSettingChange(uFlags, lpszSection);
	
	CalcSysButtonSize ();
	Invalidate ();
	UpdateWindow ();
}
//**********************************************************************************
int CBCGPMenuBar::CalcMaxButtonHeight ()
{
	m_bHaveButtons = FALSE;

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

		if (!pButton->IsKindOf (RUNTIME_CLASS (CBCGPToolbarMenuButtonsButton)) &&
			!pButton->IsKindOf (RUNTIME_CLASS (CBCGPToolbarSystemMenuButton)) &&
			pButton->m_bImage && pButton->IsDrawImage ())
		{
			m_bHaveButtons = TRUE;
			break;
		}
	}

	return GetRowHeight ();
}
//*********************************************************************************
BOOL CBCGPMenuBar::BuildOrigItems (UINT uiMenuResID)
{
	while (!m_OrigButtons.IsEmpty ())
	{
		delete m_OrigButtons.RemoveHead ();
	}

	if (GetWorkspace () == NULL ||
		!GetWorkspace ()->IsResourceSmartUpdate ())
	{
		return FALSE;
	}
	
	CMenu menu;
	if (!menu.LoadMenu (uiMenuResID))
	{
		ASSERT (FALSE);
		return FALSE;
	}

	int iCount = (int) menu.GetMenuItemCount ();
	for (int i = 0; i < iCount; i ++)
	{
		UINT uiID = menu.GetMenuItemID (i);

		CString strText;

#ifdef _DEBUG
		menu.GetMenuString (i, strText, MF_BYPOSITION);
#endif

		switch (uiID)
		{
		case -1:	// Pop-up menu
			{
				CMenu* pPopupMenu = menu.GetSubMenu (i);
				ASSERT (pPopupMenu != NULL);

				m_OrigButtons.AddTail (
					new CBCGPToolbarMenuButton (0, pPopupMenu->GetSafeHmenu (), -1, strText));
			}
			break;

		case 0:		// Separator
			{
				CBCGPToolbarButton* pButton = new CBCGPToolbarButton;
				ASSERT (pButton != NULL);

				pButton->m_nStyle = TBBS_SEPARATOR;
				m_OrigButtons.AddTail (pButton);
			}
			break;

		default:	// Regular command

			m_OrigButtons.AddTail (new CBCGPToolbarButton (uiID, -1, strText));
			break;
		}
	}

	return TRUE;
}
//*****************************************************************************************
void CBCGPMenuBar::UpdateMDIChildrenMenus (CMultiDocTemplate* pTemplate)
{
	ASSERT_VALID (pTemplate);

	for (POSITION pos = pTemplate->GetFirstDocPosition (); pos != NULL;)
	{
		CDocument* pDoc = pTemplate->GetNextDoc (pos);
		ASSERT_VALID (pDoc);

		// assumes 1 doc per frame
		for (POSITION posView = pDoc->GetFirstViewPosition (); posView != NULL;)
		{
			CView* pView = pDoc->GetNextView (posView);
			ASSERT_VALID (pView);

			CMDIChildWnd* pFrame = DYNAMIC_DOWNCAST (CMDIChildWnd, pView->GetParentFrame());
			if (pFrame != NULL)
			{
				pFrame->SetHandles (pTemplate->m_hMenuShared, pTemplate->m_hAccelTable);
			}
		}
	}
}
//****************************************************************************************
BOOL CBCGPMenuBar::IsPureMenuButton (CBCGPToolbarButton* pButton) const
{
	ASSERT_VALID (pButton);
	return m_bMenuMode || pButton->IsKindOf (RUNTIME_CLASS (CBCGPToolbarMenuButton));
}

⌨️ 快捷键说明

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