sleepp
sleepp

Reputation: 47

Disabling customization only on MFC menu bar

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.

Upvotes: 0

Views: 1834

Answers (2)

xMRi
xMRi

Reputation: 15375

Set the member variable m_bDisableCustomize to TRUE.

Upvotes: 2

sergiol
sergiol

Reputation: 4335

I would use

EnableCustomizeButton(FALSE, NULL);

after window creation.

Upvotes: 0

Related Questions