CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 1999
    Posts
    1

    Popup Menu does not work with OnUpdate...() methods

    Hey Folks !

    Whenever I use a Popup Menu, i.e. over a CTreeCtrl, the accompanied menuitems will not be updated by the OnUpdate...() methods. That means all items are allways active. I debuged that and realized that the OnUpdate...() methods are called when then a single item was selected by mouse or keyboard !

    Does anybody know about this problem or has a solution ?

    kug


  2. #2
    Join Date
    Apr 1999
    Location
    CA, USA
    Posts
    78

    Re: Popup Menu does not work with OnUpdate...() methods

    I found the same problem before. I guess the best way to solve it is to disable/enable the popup menu items when you create the popup menu, not using OnUpdate.. function. For example, you want to disable "Save" menu item for pooup menu, use EnableMenuItem to disable it.

    void CMyView::OnContextMenu(CWnd* pWnd, CPoint point)
    {
    // TODO: Add your message handler code here
    CMenu menuText;
    menuText.LoadMenu(IDR_POPUPMENU);
    // remove the header of menu
    CMenu* pMenuPopup = menuText.GetSubMenu(0);
    menuText.RemoveMenu(0, MF_BYPOSITION);

    // only enable necessary menu items to user
    if(m_bNotSave == TRUE)
    // don't need to enable "Save" menu item pMenuPopup->EnableMenuItem(ID_FILE_SAVE, MF_GRAYED|MF_BYCOMMAND);


    pMenuPopup->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, pWnd, NULL);
    }

    //..........................

    Hope this will help. Good luck.

    Lynx



  3. #3
    Join Date
    Apr 1999
    Posts
    8

    Re: Popup Menu does not work with OnUpdate...() methods

    I met the same questions too,I finally used removemenu function,more ID!some enabled,some grayed!but I thought it was not a good way.



  4. #4
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Popup Menu does not work with OnUpdate...() methods

    I ran into the same problem, so I checked if the commands were applicable or not, and if they were, I enabled them, and if not I disabled them
    Voila....

    Sally


  5. #5
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Popup Menu does not work with OnUpdate...() methods

    I would like to explain it in more detail fashion but I do not have enough time.
    Handling of popup menus in the view is different than regular menu. If you had checked message routing, the way OnUpdate… is dispatched, it is looking for an ACTIVE View. When application is idle, view may not be active, frame is. And to your surprise, main frame window is active. So when you invoke call to pop menu up, you are not getting OnUpdate…, and this is quite expected view behavior.

    Try to this in your View class:

    CMenu menuText;
    CWnd* pActiveWnd = SetActiveWindow(); // <- this will set view active and show you window that was active. Set breakpoint here to see.

    menuText.LoadMenu(IDR_POPUP_I);
    CMenu* pMenuPopup = menuText.GetSubMenu(0);

    pMenuPopup->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this/*or pWnd from parameter list*/, NULL);




    Another thing you can do is to handle popup menu in chold frame class. Child frame will receive notification, since framework dowz not look for a active frame. Remember, you can invoke it in the view, but show different window to process command messages by setting 4-th parameter in TrackPopupMenu call. For example this will invoke menu in the view, but all command messages including updates will be dispatched to Child Frame (assuming you have simple view-frame architecture):

    pMenuPopup->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, GetParent(), NULL);




    Please let me know if this resolved your problem.
    Good luck.


    John Cz
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured