1

1> I could remove top level menu item (along with its sub-menus) in MFC MDI application using below code.

void CMainFrame::OnRemoveMyMenu()
{
    ////////////////////////////////////////////////////////////////////////
    CString sMenuText = _T("");
    BOOL bReturn = FALSE;

    const CMFCMenuBar *pMenuBar = GetMenuBar();

    HMENU hMainMenu = NULL;
    HMENU hSubMenu = NULL;

    hMainMenu = pMenuBar->GetHMenu();
    ASSERT(hMainMenu);

    RemoveMenu(hMainMenu, 3, MF_BYPOSITION);
    //----------------------------------------------------------------------
}

2> However, it works only on AppWizard created IDR_MAINFRAME menu. It does "not" work on another menu created in Resources by AppWizard, mainly IDR_<>TYPE menu (which is the Menu displayed with MDI window is put on).

3> I tried to call similar code within different places in View as well as call the same code as above, placed in MainFrame from View. But it did not work.

4> Can somebody given hint as to what I am missing?

Thanks a lot

KA.Mumbai

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
KA.Mumbai
  • 11
  • 2
  • *"It does "not" work"* is not a problem statement. Please see [ask] and provide a [mcve]. – IInspectable Jun 07 '22 at 12:09
  • >>>But it did not work. Meaning: the said call from View, as mentioned in #3 above, do not get handle to IDR_<>TYPE menu, rather it gets handle only to IDR_MAINFRAME menu. Thus it is unable to remove menu, when MDI child is up. Thanks. – KA.Mumbai Jun 07 '22 at 12:57
  • Under normal circumstances you call the appropriate Update event handlers to enable / disable the menu items on the `CView` derived class. I have never had a need to remove an actual menu itself from the bar. – Andrew Truckle Jun 07 '22 at 13:48
  • Hi Andrew: As I have to remove top level menu (which contains 25+ sub-menus), removing it is easy, as that will avoid 25+ disable/hide calls individually. – KA.Mumbai Jun 07 '22 at 14:00
  • Have you tried debugging and walking the menu items? You see, the main frame is responsible for the menu and there is only one menu. So it must dynamically re-load the right menu resource. Walk the menu items and display their names / index values and compare againt your MFC resources. – Andrew Truckle Jun 07 '22 at 14:11
  • 1
    OK, let me re-do this Andrew. Thanks a lot for suggestion. I will certainly. – KA.Mumbai Jun 07 '22 at 15:29
  • This needs to be done responding dynamically to `WM_INITMENUPOPUP` or `WM_INITPOPUP`, depending whether you are using a `CMFCMenuBar` or not. – sergiol Jun 08 '22 at 13:14
  • OK, great input Sergiol. I shall try this out on this weekend. Thanks a lot for your time. – KA.Mumbai Jun 09 '22 at 15:06

0 Answers0