In this tip, you will see the steps to disable MFC SDI/MDI submenu.
The example code is hosted at Github.
Follow the steps to disable your MFC submenu in the SDI/MDI application. First, create a submenu by typing in the menu editor in Visual Studio.
Right-click on the new submenu to bring up the context menu and select the "Add Event Handler".
In the event handler dialog, in the class dropdown, select CMainFrame
.. And in the Message Type dropdown, select UPDATE_COMMAND_UI
and click OK button.
This function handler is added by the event handler dialog.
void CMainFrame::OnUpdateFileMymenu(CCmdUI* pCmdUI)
{
}
Delete the comment and add this line to disable your submenu. This handler is called whenever your menu is about to be displayed.
void CMainFrame::OnUpdateFileMymenu(CCmdUI* pCmdUI)
{
pCmdUI->Enable(FALSE);
}
Build and run the application to see if the menu is disabled.
History
- 21st September, 2020: Initial version