Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How could I resolve this Problem Disabling a Menu item ?

How could I resolve this Problem Disabling a Menu item ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SherTeks
    wrote on last edited by
    #1

    I have the following two classes : 1) A CDialog derived CDlgClass 2) A CCmdTarget derived CAnotherClass I am unable to disable an item of the launched context-menu. Please follow the comments below to track the problem.

    In DlgClass.cpp

    ON_COMMAND(ID_MENUITEM1, OnMenuItemEdit1Clicked)
    ON_UPDATE_COMMAND_UI(ID_MENUITEM1, OnUpdateMenuItemEdit1)

    //On Right-clicking the dialog, this function is called
    VOID CDlgClass::OnContextMenu(CWnd* pWnd, CPoint point)
    {
    //Here, another class' ShowContextMenu is called to load the menu and show it
    m_pAnotherClass->ShowContextMenu( this, point);
    }

    void CDlgClass::OnMenuItemEdit1Clicked()
    {
    //Control reaches here when menu item 1 is clicked
    }

    void CDlgClass::OnUpdateMenuItemEdit1(CCmdUI* pCmdUI)
    {
    //Control is expected to reach here before the menu launches but doesn't do so. Why?
    //I am expecting menu Item 1 to be disabled before it shows up.

    pCmdUI->Enable(FALSE);
    

    }

    In AnotherClass.cpp

    VOID CAnotherClass::ShowContextMenu(CWnd *pDlg, CPoint point)
    {
    CMenu cmCtxtMenu;

    cmCtxtMenu.LoadMenu(IDR\_MENU\_OPTIONS);
    	
    CMenu \*pcmPopupMenu = cmCtxtMenu.GetSubMenu(0);
    ASSERT(pcmPopupMenu);
    
    pcmPopupMenu->TrackPopupMenu (TPM\_RIGHTBUTTON|TPM\_LEFTALIGN, point.x, point.y, pDlg );
    

    }

    What could be the problem with disabling the menu item although I could actually activate the menu item handler properly? The function CDlgClass::OnUpdateMenuItemEdit1(CCmdUI* pCmdUI) itself is not getting called before launch of the menu, when the menu is loaded in a different class. What could be the reason ? Thanks in Advance.

    M 1 Reply Last reply
    0
    • S SherTeks

      I have the following two classes : 1) A CDialog derived CDlgClass 2) A CCmdTarget derived CAnotherClass I am unable to disable an item of the launched context-menu. Please follow the comments below to track the problem.

      In DlgClass.cpp

      ON_COMMAND(ID_MENUITEM1, OnMenuItemEdit1Clicked)
      ON_UPDATE_COMMAND_UI(ID_MENUITEM1, OnUpdateMenuItemEdit1)

      //On Right-clicking the dialog, this function is called
      VOID CDlgClass::OnContextMenu(CWnd* pWnd, CPoint point)
      {
      //Here, another class' ShowContextMenu is called to load the menu and show it
      m_pAnotherClass->ShowContextMenu( this, point);
      }

      void CDlgClass::OnMenuItemEdit1Clicked()
      {
      //Control reaches here when menu item 1 is clicked
      }

      void CDlgClass::OnUpdateMenuItemEdit1(CCmdUI* pCmdUI)
      {
      //Control is expected to reach here before the menu launches but doesn't do so. Why?
      //I am expecting menu Item 1 to be disabled before it shows up.

      pCmdUI->Enable(FALSE);
      

      }

      In AnotherClass.cpp

      VOID CAnotherClass::ShowContextMenu(CWnd *pDlg, CPoint point)
      {
      CMenu cmCtxtMenu;

      cmCtxtMenu.LoadMenu(IDR\_MENU\_OPTIONS);
      	
      CMenu \*pcmPopupMenu = cmCtxtMenu.GetSubMenu(0);
      ASSERT(pcmPopupMenu);
      
      pcmPopupMenu->TrackPopupMenu (TPM\_RIGHTBUTTON|TPM\_LEFTALIGN, point.x, point.y, pDlg );
      

      }

      What could be the problem with disabling the menu item although I could actually activate the menu item handler properly? The function CDlgClass::OnUpdateMenuItemEdit1(CCmdUI* pCmdUI) itself is not getting called before launch of the menu, when the menu is loaded in a different class. What could be the reason ? Thanks in Advance.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      SherTeks wrote:

      The function CDlgClass::OnUpdateMenuItemEdit1(CCmdUI* pCmdUI) itself is not getting called

      See this post[^]. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups