0

When using the MFC feature pack in VS2010, is it possible to disable the customization feature on the CMFCMenuBar but leave it enabled on the toolbars? We don't want users dragging menus around but they're free to change the toolbars.

We disabled saving the state of the CMFCMenuBar into the registry on exit but the menus could still be moved around or removed during runtime.

Update: Following xMRi's answer, I set m_bDisableCustomize to TRUE in a derived menu class's constructor. I noticed there was a redrawing issue where clicking on the menu during the customization would draw black boxes all over the menus. That led me to http://www.bcgsoft.com/cgi-bin/forum/topic.asp?TOPIC_ID=2643

I didn't want to modify the MFC source code so I handled the message instead:

//{{AFX_MSG_MAP(CMyMFCMenuBar)
BEGIN_MESSAGE_MAP(CMyMFCMenuBar, CMFCMenuBar)
    ON_WM_LBUTTONDOWN()
    ON_WM_CONTEXTMENU()
END_MESSAGE_MAP()
//}}AFX_MSG_MAP

void CMyMFCMenuBar::OnLButtonDown(UINT nFlags, CPoint point)
{
    CMFCMenuBar::OnLButtonDown(nFlags, point);
    Invalidate();
}

void CMyMFCMenuBar::OnContextMenu(CWnd* pWnd, CPoint pos)
{
    if (IsCustomizeMode())
        return;
    CMFCMenuBar::OnContextMenu(pWnd, pos);
}

and that seems to fix the redrawing issue. Please let me know if there's a better way to fix the redrawing issue.

sleepp
  • 47
  • 1
  • 7

2 Answers2

2

Set the member variable m_bDisableCustomize to TRUE.

xMRi
  • 14,982
  • 3
  • 26
  • 59
  • Setting m_bDisableCustomize to TRUE worked but there was a redrawing issue if the menus were clicked during customization. – sleepp Oct 29 '13 at 22:15
  • If the user right clicks on the menu bar, they can still modify (rename, delete) the top level buttons even with the variable set. Is there a way to disable the right click context menu during customization mode? – sleepp Nov 04 '13 at 18:14
  • There is a message named AFX_WM_TOOLBARMENU. Try to handle it in the parent frame. Afaik this is the context menu that offers the problematic menu. Ort check the path of OnContextMenu... – xMRi Nov 05 '13 at 06:12
  • I had tried AFX_WM_TOOLBARMENU before and it was only for the context menu before the customize dialog is opened. But handing WM_CONTEXTMENU and OnContextMenu in the menu bar class worked great! Thanks! – sleepp Nov 05 '13 at 15:09
0

I would use

EnableCustomizeButton(FALSE, NULL);

after window creation.

sergiol
  • 4,122
  • 4
  • 47
  • 81