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

    ON_UPDATE_COMMAND_UI question



    Hi:


    I have an output window that's a CRichEditCtrl, that I've created a context sensitive menu for. One of the options is 'Copy' to copy the selection in the window to the clipboard. When the user selects 'Copy' from the context menu, it goes and calls Copy(). This works fine, however I'd like to add an ON_UPDATE_COMMAND_UI handler to properly gray out the menu choice when nothing is selected. The problem I'm having is that my ON_UPDATE_COMMAND_UI code seems to get executed after the user makes a menu choice, not before, so 'Copy' is never grayed out. Is there some way around this problem?


    thanks,

    -Matt

  2. #2
    Join Date
    Apr 1999
    Posts
    11

    Re: ON_UPDATE_COMMAND_UI question

    If you create a context menu for your RichEditCtrl, you can disable the "Copy" menu when user right click mouse, if there is no selection in the control.
    For example:

    void CMyClass::OnContextMenu(CWnd* pWnd, CPoint point)
    {
    CMenu menuText;
    menuText.LoadMenu(IDR_ID_POPMENU);
    // remove the header of menu
    CMenu* pMenuPopup = menuText.GetSubMenu(0);
    menuText.RemoveMenu(0, MF_BYPOSITION);

    // only enable necessary menu items to user
    if(m_bTestSelection == FALSE){
    // no text is selected
    // disable the "Copy" menu item
    pMenuPopup->EnableMenuItem(ID_EDIT_COPY,
    MF_GRAYED|MF_BYCOMMAND);
    }
    pMenuPopup->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, pWnd, NULL);
    }

    //...........
    That should disable the "Copy" menu, if the m_bTextSelection is false.
    Hope this will help. Good luck.

    Allen


  3. #3
    Guest

    Re: ON_UPDATE_COMMAND_UI question

    I have the same problem as the original poster(Matthew Smith). So far I have used a solution similar to the one Allen is proposing, but do it really have to be like that? Isn't this what the ON_UPDATE_COMMAND_UI is meant to solve?
    In my case things get quite messy when I have to do all the work manually (I have several levels of submenus on the top level popup menu). It would have been much nicer if I could get the OnCommandUpdateUi scheme to work.
    I suspect that my problems are related to the fact that the main menu does not have the menu entries that are used in the popup menu. When the framework is routing the message it discards the message because it is not in the main menu, but I have not been able to verify this.

    If anyone knows how to get this to work properly if would be happy to hear about it.

    thanks,
    Olav



  4. #4
    Join Date
    Apr 1999
    Posts
    3

    Re: ON_UPDATE_COMMAND_UI question

    This is just a guess, but have you tried putting the popup menu in the main menubar
    and hiding it (non-visible)? This may prevent the message from being discarded.


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