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

📄 bcgpmenubar.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		GetParentFrame ()->RecalcLayout ();
		Invalidate ();
		UpdateWindow ();
	}
	
	AdjustLayout ();

	return TRUE;
}
//*****************************************************************************************
void CBCGPMenuBar::ResetImages ()
{
	ASSERT (m_hDefaultMenu != NULL);

	g_menuHash.SaveMenuBar (m_hMenu, this);

	CDocManager* pDocManager = AfxGetApp ()->m_pDocManager;
	if (pDocManager != NULL)
	{
		//---------------------------------------
		// Walk all templates in the application:
		//---------------------------------------
		for (POSITION pos = pDocManager->GetFirstDocTemplatePosition (); pos != NULL;)
		{
			CBCGPMultiDocTemplate* pTemplate = 
				(CBCGPMultiDocTemplate*) pDocManager->GetNextDocTemplate (pos);
			ASSERT_VALID (pTemplate);
			ASSERT_KINDOF (CDocTemplate, pTemplate);

			//-----------------------------------------------------
			// We are interessing CMultiDocTemplate objects with
			// the sahred menu only....
			//-----------------------------------------------------
			if (!pTemplate->IsKindOf (RUNTIME_CLASS (CMultiDocTemplate)) ||
				pTemplate->m_hMenuShared == NULL)
			{
				continue;
			}

			if (g_menuHash.LoadMenuBar (pTemplate->m_hMenuShared, this))
			{
				CBCGPToolBar::ResetImages ();
				g_menuHash.SaveMenuBar (pTemplate->m_hMenuShared, this);
			}
		}
	}

	//--------------------
	// Reset default menu:
	//--------------------
	if (g_menuHash.LoadMenuBar (m_hDefaultMenu, this))
	{
		CBCGPToolBar::ResetImages ();
		g_menuHash.SaveMenuBar (m_hDefaultMenu, this);
	}

	//----------------------
	// Restore current menu:
	//----------------------
	if (m_hMenu != NULL && g_menuHash.LoadMenuBar (m_hMenu, this))
	{
		GetParentFrame ()->RecalcLayout ();
		Invalidate ();
		UpdateWindow ();
	}
}
//*****************************************************************************************
void CBCGPMenuBar::OnLButtonDown(UINT nFlags, CPoint point) 
{
	int iHit = HitTest (point);

	//--------------------------------------------------------
	// Disable control bar dragging if any menues are dropped!
	//--------------------------------------------------------
	if (iHit < 0 &&	// Click outside of buttons
		GetDroppedDownMenu () != NULL)
	{
//		Do nothing
		CBCGPToolBar::OnLButtonDown(nFlags, point);
	}
	else
	{		
		CBCGPToolBar::OnLButtonDown(nFlags, point);
	}
}
//****************************************************************************************
BOOL CBCGPMenuBar::RestoreOriginalstate ()
{
	HMENU hMenuCurr = m_hMenu;
	
	if (m_hMenu != NULL)
	{
		g_menuHash.SaveMenuBar (m_hMenu, this);
	}


	//-----------------------
	// Save customize button:
	//-----------------------
	CCustomizeButton* pCustomizeBtn = NULL;
	if (m_pCustomizeBtn != NULL)
	{
		ASSERT_VALID (m_pCustomizeBtn);
		ASSERT (m_pCustomizeBtn == m_Buttons.GetTail ());	// Should be last

		pCustomizeBtn = new CCustomizeButton;
		pCustomizeBtn->CopyFrom (*m_pCustomizeBtn);
	}



	CBCGPMDIFrameWnd* pWndParentMDIFrame = 
		DYNAMIC_DOWNCAST (CBCGPMDIFrameWnd, m_pParentWnd);

	if (g_pTearOffMenuManager != NULL)
	{
		g_pTearOffMenuManager->Reset (NULL);
	}

	BOOL bCurrMenuIsRestored = FALSE;
	CDocTemplate* pActiveTemplate = NULL;

	//------------------------------------------------------------
	// Save current maximize mode (system buttons are not saved!):
	//------------------------------------------------------------
	BOOL bMaximizeMode = m_bMaximizeMode;
	SetMaximizeMode (FALSE);

	CDocManager* pDocManager = AfxGetApp ()->m_pDocManager;
	if (pDocManager != NULL)
	{
		//------------------------------------
		// Find an active document's template:
		//------------------------------------
		CMDIFrameWnd* pParentFrame = DYNAMIC_DOWNCAST (CMDIFrameWnd, m_pParentWnd);
		if (pParentFrame != NULL && pParentFrame->MDIGetActive () != NULL)
		{
			CDocument* pActiveDoc = pParentFrame->MDIGetActive ()->GetActiveDocument ();
			if (pActiveDoc != NULL)
			{
				pActiveTemplate = pActiveDoc->GetDocTemplate ();
			}
		}

		//---------------------------------------
		// Walk all templates in the application:
		//---------------------------------------
		for (POSITION pos = pDocManager->GetFirstDocTemplatePosition (); pos != NULL;)
		{
			CBCGPMultiDocTemplate* pTemplate = 
				(CBCGPMultiDocTemplate*) pDocManager->GetNextDocTemplate (pos);
			ASSERT_VALID (pTemplate);
			ASSERT_KINDOF (CDocTemplate, pTemplate);

			//-----------------------------------------------------
			// We are interessing CMultiDocTemplate objects with
			// the shared menu only....
			//-----------------------------------------------------
			if (!pTemplate->IsKindOf (RUNTIME_CLASS (CMultiDocTemplate)) ||
				pTemplate->m_hMenuShared == NULL)
			{
				continue;
			}

			UINT uiMenuResId = pTemplate->GetResId ();
			ASSERT (uiMenuResId != 0);

			//-------------------------------------
			// Restore original menu from resource:
			//-------------------------------------
			HINSTANCE hInst = AfxFindResourceHandle (
				MAKEINTRESOURCE (uiMenuResId), RT_MENU);

			BOOL bCurr = (pActiveTemplate == pTemplate);

			HMENU hmenuSharedOld = pTemplate->m_hMenuShared;
			pTemplate->m_hMenuShared = ::LoadMenu (hInst, MAKEINTRESOURCE (uiMenuResId));

			CreateFromMenu (pTemplate->m_hMenuShared, FALSE);
			g_menuHash.SaveMenuBar (pTemplate->m_hMenuShared, this);

			if (bCurr)
			{
				hMenuCurr = pTemplate->m_hMenuShared;
				bCurrMenuIsRestored = TRUE;
			}

			//----------------------------------------------
			// Update shared menus in all MDI child windows:
			//----------------------------------------------
			UpdateMDIChildrenMenus (pTemplate);

			if (hmenuSharedOld != NULL)
			{
				ASSERT (::IsMenu (hmenuSharedOld));
				g_menuHash.RemoveMenu (hmenuSharedOld);
				::DestroyMenu (hmenuSharedOld);
			}
		}
	}

	//----------------------
	// Load defualt menubar:
	//----------------------
	if (m_uiDefMenuResId != 0)
	{
		HINSTANCE hInst = AfxFindResourceHandle (
			MAKEINTRESOURCE (m_uiDefMenuResId), RT_MENU);

		HMENU hOldDefaultMenu = m_hDefaultMenu;

		m_hDefaultMenu = ::LoadMenu (hInst, MAKEINTRESOURCE (m_uiDefMenuResId));

		OnDefaultMenuLoaded(m_hDefaultMenu);

		CreateFromMenu (m_hDefaultMenu, TRUE);
		g_menuHash.SaveMenuBar (m_hDefaultMenu, this);

		if (!bCurrMenuIsRestored)
		{
			hMenuCurr = m_hDefaultMenu;
		}

		if (pWndParentMDIFrame != NULL)
		{
			pWndParentMDIFrame->m_hMenuDefault = m_hDefaultMenu;
			pWndParentMDIFrame->m_Impl.m_hDefaultMenu = m_hDefaultMenu;
		}

		CFrameWnd* pWndParentFrame = DYNAMIC_DOWNCAST (CFrameWnd, m_pParentWnd);
		if (pWndParentFrame != NULL)
		{
			pWndParentFrame->m_hMenuDefault = m_hDefaultMenu;
		}

		if (hOldDefaultMenu != NULL)
		{
			ASSERT (::IsMenu (hOldDefaultMenu));

			g_menuHash.RemoveMenu (hOldDefaultMenu);
			::DestroyMenu (hOldDefaultMenu);
		}
	}

	//----------------------
	// Restore current menu:
	//----------------------
	if (g_menuHash.LoadMenuBar (hMenuCurr, this))
	{
		m_hMenu = hMenuCurr;

		if (!bMaximizeMode)
		{
			GetParentFrame ()->RecalcLayout ();
			Invalidate ();
			UpdateWindow ();
		}
	}

	if (pWndParentMDIFrame != NULL)
	{
		pWndParentMDIFrame->OnUpdateFrameMenu (m_hMenu);
	}

	if (bMaximizeMode)
	{
		RestoreMaximizeMode ();
	}

#ifndef BCG_NO_CUSTOMIZATION

	if (m_pMenuPage != NULL)
	{
		ASSERT_VALID (m_pMenuPage);
		m_pMenuPage->SelectMenu (pActiveTemplate, FALSE /* Don't save cur. menu */);
	}

#endif // BCG_NO_CUSTOMIZATION


	//--------------------------
	// Restore customize button:
	//--------------------------
	if (pCustomizeBtn != NULL)
	{
		InsertButton (pCustomizeBtn);
		m_pCustomizeBtn = pCustomizeBtn;
		AdjustLayout();
		AdjustSizeImmediate ();
	}

	return TRUE;
}
//********************************************************************************************
void CBCGPMenuBar::SetDefaultMenuResId (UINT uiResId)
{
	m_uiDefMenuResId = uiResId;
}
//******************************************************************
BOOL CBCGPMenuBar::PreTranslateMessage(MSG* pMsg) 
{
	if (pMsg->message == WM_KEYDOWN)
	{
		//-----------------------------------------------------------
		// Fisrt, try to move keyboard control to the drop-down menu:
		//-----------------------------------------------------------
		CBCGPToolbarMenuButton* pMenuButon = GetDroppedDownMenu ();
		if (pMenuButon != NULL)
		{
			return CBCGPBaseControlBar::PreTranslateMessage(pMsg);
		}

		int iTotalItems = GetCount ();
		if (m_bMaximizeMode)
		{
			iTotalItems -= m_nSystemButtonsNum;
		}

		if (m_iHighlighted >= 0 && m_iHighlighted < iTotalItems)
		{
			int iButton = m_iHighlighted;

			switch (pMsg->wParam)
			{
			case VK_ESCAPE:
				{
					Deactivate ();
					RestoreFocus ();
					m_bShowAllCommands = FALSE;
				}
				break;

			case VK_RIGHT:
				if (++ m_iHighlighted >= iTotalItems)
				{
					m_iHighlighted = 0;
				}

				InvalidateButton (iButton);
				InvalidateButton (m_iHighlighted);
				UpdateWindow ();
				break;

			case VK_LEFT:
				if (-- m_iHighlighted < 0)
				{
					m_iHighlighted = iTotalItems - 1;
				}

				InvalidateButton (iButton);
				InvalidateButton (m_iHighlighted);
				UpdateWindow ();
				break;

			case VK_DOWN:
				DropDownMenu (GetButton (m_iHighlighted));
				return TRUE;

			case VK_RETURN:
				if (!DropDownMenu (GetButton (m_iHighlighted)))
				{
					ProcessCommand (GetButton (m_iHighlighted));
				}
				return TRUE;

			default:
				if (TranslateChar ((int) pMsg->wParam))
				{
					return TRUE;
				}
			}
		}
	}

	return CBCGPToolBar::PreTranslateMessage(pMsg);
}
//**************************************************************************************
void CBCGPMenuBar::OnSetFocus(CWnd* pOldWnd) 
{
	CBCGPToolBar::OnSetFocus(pOldWnd);

	if (GetDroppedDownMenu () == NULL)
	{
		GetOwner()->SendMessage (WM_SETMESSAGESTRING, AFX_IDS_IDLEMESSAGE);

		int iFirstItem = (GetSystemMenu () != NULL) ? 1 : 0;
		if (m_iHighlighted < 0 && iFirstItem < GetCount ())
		{
			m_iHighlighted = iFirstItem;
			InvalidateButton (iFirstItem);
		}
	}
}
//**************************************************************************************
BOOL CBCGPMenuBar::Create(CWnd* pParentWnd,
			DWORD dwStyle,
			UINT nID)
{
	m_pParentWnd = pParentWnd;
	return CBCGPToolBar::Create (pParentWnd, dwStyle, nID);
}
//***************************************************************************************
BOOL CBCGPMenuBar::CreateEx(CWnd* pParentWnd, DWORD dwCtrlStyle,
		DWORD dwStyle,
		CRect rcBorders,
		UINT nID)
{
	m_pParentWnd = pParentWnd;
	return CBCGPToolBar::CreateEx (pParentWnd, dwCtrlStyle, dwStyle, rcBorders, nID);
}
//***************************************************************************************
CSize CBCGPMenuBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
	if (m_Buttons.IsEmpty ())
	{
		return GetButtonSize ();
	}

	DWORD dwMode = bStretch ? LM_STRETCH : 0;
	dwMode |= bHorz ? LM_HORZ : 0;

	return CalcLayout (dwMode);
}
//*****************************************************************************************
BOOL CBCGPMenuBar::OnSetDefaultButtonText (CBCGPToolbarButton* pButton)
{
	ASSERT_VALID (pButton);

	CString strText;
	if (FindMenuItemText (m_hMenu, pButton->m_nID, strText))
	{
		pButton->m_strText = strText;
		return TRUE;
	}

⌨️ 快捷键说明

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