📄 bcgpmenubar.cpp
字号:
}
//***************************************************************************************
void CBCGPMenuBar::RestoreMaximizeMode (BOOL bRecalcLayout)
{
if (m_bMaximizeMode)
{
return;
}
int nSystemButtonsNum = 0;
if (m_hSysMenu != NULL)
{
CMDIFrameWnd* pParentFrame = DYNAMIC_DOWNCAST (CMDIFrameWnd, m_pParentWnd);
if (pParentFrame != NULL && pParentFrame->MDIGetActive () != NULL)
{
LONG style = ::GetWindowLong(*pParentFrame->MDIGetActive (), GWL_STYLE);
CBCGPToolbarSystemMenuButton button (m_hSysMenu, m_hSysIcon);
InsertButton (button, 0);
if (style & WS_MINIMIZEBOX)
{
InsertButton (CBCGPToolbarMenuButtonsButton (SC_MINIMIZE));
nSystemButtonsNum++;
}
if (style & WS_MAXIMIZEBOX)
{
InsertButton (CBCGPToolbarMenuButtonsButton (SC_RESTORE));
nSystemButtonsNum++;
}
CBCGPToolbarMenuButtonsButton closeButton (SC_CLOSE);
MENUITEMINFO menuInfo;
ZeroMemory(&menuInfo,sizeof(MENUITEMINFO));
menuInfo.cbSize = sizeof(MENUITEMINFO);
menuInfo.fMask = MIIM_STATE;
if (!::GetMenuItemInfo(m_hSysMenu, SC_CLOSE, FALSE, &menuInfo) ||
(menuInfo.fState & MFS_GRAYED) ||
(menuInfo.fState & MFS_DISABLED))
{
closeButton.m_nStyle |= TBBS_DISABLED;
}
InsertButton (closeButton);
nSystemButtonsNum++;
}
}
m_bMaximizeMode = TRUE;
m_nSystemButtonsNum = m_nSystemButtonsNumSaved;
ASSERT (m_nSystemButtonsNum == nSystemButtonsNum);
if (bRecalcLayout)
{
GetParentFrame ()->RecalcLayout ();
Invalidate ();
UpdateWindow ();
}
}
//***************************************************************************************
void CBCGPMenuBar::AdjustLocations ()
{
CBCGPToolBar::AdjustLocations ();
if (!m_bMaximizeMode)
{
return;
}
CRect rectClient;
GetClientRect (&rectClient);
BOOL bHorz = GetCurrentAlignment () & CBRS_ORIENT_HORZ ? TRUE : FALSE;
int iButtonWidth = m_szSystemButton.cx;
int iButtonHeight = m_szSystemButton.cy;
POSITION pos = m_Buttons.GetTailPosition ();
CRect rect = rectClient;
rectClient.SetRectEmpty ();
CalcInsideRect (rectClient, bHorz);
if (!bHorz)
{
rect.bottom += rectClient.Height ();
}
rect.left = rect.right - iButtonWidth;
rect.top = rect.bottom - iButtonHeight;
if (m_pCustomizeBtn != NULL)
{
m_Buttons.GetPrev(pos);
}
for (int i = 0; i < m_nSystemButtonsNum; i ++)
{
ASSERT (pos != NULL);
CBCGPToolbarMenuButtonsButton* pButton =
(CBCGPToolbarMenuButtonsButton*) m_Buttons.GetPrev (pos);
ASSERT_KINDOF (CBCGPToolbarMenuButtonsButton, pButton);
pButton->SetRect (rect);
if (bHorz)
{
rect.OffsetRect (-iButtonWidth - 1, 0);
}
else
{
rect.OffsetRect (0, -iButtonHeight - 1);
}
}
}
//***************************************************************************************
BOOL CBCGPMenuBar::OnSendCommand (const CBCGPToolbarButton* pButton)
{
CBCGPToolbarMenuButtonsButton* pSysButton =
DYNAMIC_DOWNCAST (CBCGPToolbarMenuButtonsButton, pButton);
if (pSysButton == NULL)
{
return FALSE;
}
if (pSysButton->m_uiSystemCommand != SC_CLOSE &&
pSysButton->m_uiSystemCommand != SC_MINIMIZE &&
pSysButton->m_uiSystemCommand != SC_RESTORE)
{
ASSERT (FALSE);
return TRUE;
}
CMDIFrameWnd* pParentFrame =
DYNAMIC_DOWNCAST (CMDIFrameWnd, m_pParentWnd);
if (pParentFrame == NULL)
{
MessageBeep ((UINT) -1);
return TRUE;
}
CMDIChildWnd* pChild = pParentFrame->MDIGetActive ();
ASSERT_VALID (pChild);
pChild->SendMessage (WM_SYSCOMMAND, pSysButton->m_uiSystemCommand);
return TRUE;
}
//*************************************************************************************
int CBCGPMenuBar::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
{
ASSERT_VALID(this);
int nHit = ((CBCGPMenuBar*)this)->HitTest(point);
if (nHit != -1)
{
CBCGPToolbarButton* pButton = GetButton (nHit);
if (pButton == NULL ||
pButton->IsKindOf (RUNTIME_CLASS (CBCGPToolbarMenuButton)))
{
//-----------------------------------
// Don't show tooltips on menu items!
//-----------------------------------
return -1;
}
}
return CBCGPToolBar::OnToolHitTest (point, pTI);
}
//*************************************************************************************
int CBCGPMenuBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CBCGPToolBar::OnCreate(lpCreateStruct) == -1)
return -1;
//------------------------------------
// Attach menubar to the parent frame:
//------------------------------------
//----------------------
// First, try MDI frame:
//----------------------
CBCGPMDIFrameWnd* pWndParentMDIFrame =
DYNAMIC_DOWNCAST (CBCGPMDIFrameWnd, m_pParentWnd);
if (pWndParentMDIFrame != NULL)
{
pWndParentMDIFrame->m_Impl.SetMenuBar (this);
}
else
{
CBCGPFrameWnd* pWndParentFrame =
DYNAMIC_DOWNCAST (CBCGPFrameWnd, m_pParentWnd);
if (pWndParentFrame != NULL)
{
pWndParentFrame->m_Impl.SetMenuBar (this);
}
else
{
CBCGPOleIPFrameWnd* pOleFrame =
DYNAMIC_DOWNCAST (CBCGPOleIPFrameWnd, GetParentFrame ());
if (pOleFrame != NULL)
{
pOleFrame->m_Impl.SetMenuBar (this);
}
}
}
//----------------------------
// Set default menu bar title:
//----------------------------
CBCGPLocalResource locaRes;
CString strTitle;
strTitle.LoadString (IDS_BCGBARRES_MENU_BAR_TITLE);
SetWindowText (strTitle);
//-------------------------------------------------------------
// Force the menu bar to be hiden whren the in-place editing is
// is activated (server application shows its own menu):
//-------------------------------------------------------------
SetBarStyle (GetBarStyle() | CBRS_HIDE_INPLACE);
//------------------------------
// Calculate system button size:
//------------------------------
CalcSysButtonSize ();
return 0;
}
//*************************************************************************************
BOOL CBCGPMenuBar::LoadState (LPCTSTR lpszProfileName, int nIndex, UINT /*uiID*/)
{
ASSERT (m_hDefaultMenu != NULL);
CString strProfileName = ::BCGPGetRegPath (strMenuProfile, lpszProfileName);
//------------------------------------------------------------
// Save current maximize mode (system buttons are not saved!):
//------------------------------------------------------------
BOOL bMaximizeMode = m_bMaximizeMode;
SetMaximizeMode (FALSE, NULL, FALSE);
CDocManager* pDocManager = AfxGetApp ()->m_pDocManager;
if (m_bAutoDocMenus && 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;
}
UINT uiMenuResId = pTemplate->GetResId ();
ASSERT (uiMenuResId != 0);
//---------------------------------------------------------------
// Load menubar from registry and associate it with the
// template shared menu:
//---------------------------------------------------------------
BuildOrigItems (uiMenuResId);
if (CBCGPToolBar::LoadState (strProfileName, nIndex, uiMenuResId) &&
!m_bResourceWasChanged)
{
g_menuHash.SaveMenuBar (pTemplate->m_hMenuShared, this);
}
else if (GetOwner()->GetSafeHwnd() != NULL)
{
//-----------------------------------------------------
// Addition by Oz Solomonovich:
// The following code was added to ensure that a
// BCGM_RESETMENU message will be sent to the frame the
// first time the application is loaded
//-----------------------------------------------------
m_hMenu = NULL;
CreateFromMenu (pTemplate->m_hMenuShared, FALSE);
GetOwner()->SendMessage (BCGM_RESETMENU, uiMenuResId);
g_menuHash.SaveMenuBar (pTemplate->m_hMenuShared, this);
m_hMenu = pTemplate->m_hMenuShared;
}
}
}
//----------------------
// Load defualt menubar:
//----------------------
BuildOrigItems (m_uiDefMenuResId);
if (CBCGPToolBar::LoadState (strProfileName, nIndex, 0) &&
!m_bResourceWasChanged)
{
g_menuHash.SaveMenuBar (m_hDefaultMenu, this);
}
else if (GetOwner()->GetSafeHwnd() != NULL)
{
// The following code was added to ensure that a BCGM_RESETMENU
// message will be sent to the frame the first time the application
// is loaded
m_hMenu = NULL;
CreateFromMenu (m_hDefaultMenu, TRUE);
UINT uiResID = m_uiDefMenuResId;
if (uiResID == 0)
{
// Obtain main window resource ID:
UINT uiResID = GetOwner()->SendMessage (WM_HELPHITTEST);
if (uiResID != 0)
{
uiResID -= HID_BASE_RESOURCE;
}
}
GetOwner()->SendMessage (BCGM_RESETMENU, uiResID);
g_menuHash.SaveMenuBar (m_hDefaultMenu, this);
m_hMenu = m_hDefaultMenu;
}
//----------------------
// Restore current menu:
//----------------------
BOOL bLoaded = (m_hMenu != NULL && g_menuHash.LoadMenuBar (m_hMenu, this));
if (bMaximizeMode)
{
RestoreMaximizeMode (!bLoaded); // do not recalc layout if the menu was loaded
}
if (bLoaded)
{
GetParentFrame ()->RecalcLayout ();
Invalidate ();
UpdateWindow ();
}
AdjustLayout ();
RebuildAccelerationKeys ();
return TRUE;
}
//*************************************************************************************
BOOL CBCGPMenuBar::SaveState (LPCTSTR lpszProfileName, int nIndex, UINT /*uiID*/)
{
ASSERT (m_hDefaultMenu != NULL);
CString strProfileName = ::BCGPGetRegPath (strMenuProfile, lpszProfileName);
g_menuHash.SaveMenuBar (m_hMenu, this);
//------------------------------------------------------------
// Save current maximize mode (system buttons are not saved!):
//------------------------------------------------------------
BOOL bMaximizeMode = m_bMaximizeMode;
SetMaximizeMode (FALSE, NULL, FALSE);
CDocManager* pDocManager = AfxGetApp ()->m_pDocManager;
if (m_bAutoDocMenus && 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;
}
UINT uiMenuResId = pTemplate->GetResId ();
ASSERT (uiMenuResId != 0);
//----------------------------------------------------------
// Load menubar associated with the template shared menu and
// save it in the registry:
//----------------------------------------------------------
if (g_menuHash.LoadMenuBar (pTemplate->m_hMenuShared, this))
{
BuildOrigItems (uiMenuResId);
CBCGPToolBar::SaveState (strProfileName, nIndex, uiMenuResId);
}
}
}
//-------------------
// Save default menu:
//-------------------
if (g_menuHash.LoadMenuBar (m_hDefaultMenu, this))
{
BuildOrigItems (m_uiDefMenuResId);
CBCGPToolBar::SaveState (strProfileName, nIndex, 0);
}
//----------------------
// Restore current menu:
//----------------------
BOOL bRestored = (m_hMenu != NULL && g_menuHash.LoadMenuBar (m_hMenu, this));
if (bMaximizeMode)
{
RestoreMaximizeMode (!bRestored);
}
AdjustSizeImmediate ();
if (bRestored)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -