I can't show my entire code base as it is sort of big (and people might get kind of annoyed if I published it), but here is the menu class and the references to the menu object in the main frame. The menu is implicitly created in the main frame.
I could solve the problem if the RestoreOriginalState or OnReset was called on the reset command in the Customize dialog, but for some reason they are not.
IaMenuBar.h
class IaMenuBar : public CMFCMenuBar
{
DECLARE_SERIAL(IaMenuBar)
public:
IaMenuBar();
virtual ~IaMenuBar();
virtual BOOL CreateEx( CWnd* pParentWnd,
DWORD dwCtrlStyle,
DWORD dwStyle,
CRect rcBorders,
UINT nID );
virtual BOOL RestoreOriginalState();
virtual BOOL CanBeRestored() const;
virtual BOOL LoadState(LPCTSTR lpszProfileName = NULL, int nIndex = -1, UINT uiID = (UINT)-1);
virtual BOOL SaveState(LPCTSTR lpszProfileName = NULL, int nIndex = -1, UINT uiID = (UINT)-1);
afx_msg void OnContextMenu(CWnd* pWnd, CPoint pos);
virtual void OnReset();
private:
DECLARE_MESSAGE_MAP()
};
IaMenuBar.cpp
#include "IaPch.h"
#include "IaMenuBar.h"
IMPLEMENT_SERIAL(IaMenuBar, CMFCMenuBar, VERSIONABLE_SCHEMA | 1)
BEGIN_MESSAGE_MAP(IaMenuBar, CMFCMenuBar)
ON_WM_CONTEXTMENU()
END_MESSAGE_MAP()
IaMenuBar::
IaMenuBar()
: CMFCMenuBar()
{
m_bDisableCustomize = TRUE;
}
IaMenuBar::
~IaMenuBar()
{
}
BOOL
IaMenuBar::
CreateEx( CWnd* pParentWnd,
DWORD dwCtrlStyle,
DWORD dwStyle,
CRect rcBorders,
UINT nID )
{
if (!__super::CreateEx(pParentWnd, dwCtrlStyle, dwStyle, rcBorders, nID))
{
return FALSE;
}
return TRUE;
}
BOOL
IaMenuBar::
RestoreOriginalState()
{
return TRUE;
}
BOOL
IaMenuBar::
CanBeRestored() const
{
return FALSE;
}
BOOL
IaMenuBar::
LoadState(LPCTSTR lpszProfileName , int nIndex , UINT uiID )
{
return TRUE;
}
BOOL
IaMenuBar::
SaveState(LPCTSTR lpszProfileName , int nIndex , UINT uiID )
{
return TRUE;
}
void
IaMenuBar::
OnContextMenu(CWnd* pWnd, CPoint pos)
{
if (IsCustomizeMode())
return;
CMFCMenuBar::OnContextMenu(pWnd, pos);
}
void
IaMenuBar::
OnReset()
{
if (IsCustomizeMode())
return;
CMFCMenuBar::OnReset();
}
IaMainFrame.h
class IaMainFrame :
public IfMDIFrameWnd,...
private:
...
IaMenuBar m_wndMenuBar;
IaMainFrame.cpp
int
IaMainFrame::
OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (IfMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndMenuBar.Create(this))
{
TRACE0("Failed to create menubar\n");
return -1;
}
m_wndMenuBar.SetPaneStyle(CBRS_BORDER_TOP | CBRS_TOP | CBRS_SIZE_FIXED |
CBRS_TOOLTIPS | CBRS_FLYBY);
...
m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_TOP);
DockPane(&m_wndMenuBar);
...
}
void
IaMainFrame::
UpdateMenuBar()
{
HMENU hMenu = m_wndMenuBar.GetHMenu();
m_wndMenuBar.CreateFromMenu(hMenu, TRUE, TRUE);
}