CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    [RESOLVED] Can I send OnUpdateX(CCmdUI* pCmdUI) message

    It is well documented how to override the OnUpdate notitifcation for menu items but is there any way to send that notification to the main window to get a state of a certain menu item command?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Can I send OnUpdateX(CCmdUI* pCmdUI) message

    You might be approaching the problem from the wrong angle.

    The update command handlers [typically] uses document data to determine the appropriate menu item state (disabled, enabled, checked, etc).

    Given that, since the document is available anywhere from within the app, can't you call the document method used by the update command handler directly?

  3. #3
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Can I send OnUpdateX(CCmdUI* pCmdUI) message

    No unfortunately I can't. All I can do is to send a message to the main window and get the result. I was hoping to use an already built it functionality (if OnUpdateX(CCmdUI* pCmdUI) is implemented via messages at all).

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Can I send OnUpdateX(CCmdUI* pCmdUI) message

    Calling the update handlers is an often used method to generically set various UI elements in a generic class/library without tying them to your document implementation specifically so it's not all that strange and actually better than repeating the conditions for enabling throughout your UI, even if all the conditions are nicely packed in the document.

    For a popup menu you'd do
    Code:
    CCmdUI CmdUI;
    CmdUI.m_pOther		= pCmdWnd;  // Window owning the menu
    CmdUI.m_pMenu		= pMenu;       // The CMenu pointer you're trying to update
    CmdUI.m_nIndexMax	= pMenu->GetMenuItemCount();
    for (CmdUI.m_nIndex = 0; CmdUI.m_nIndex<CmdUI.m_nIndexMax; CmdUI.m_nIndex++)
    {
    	CmdUI.m_nID = CmdUI.m_pMenu->GetMenuItemID(CmdUI.m_nIndex);
    	if (CmdUI.m_nID && CmdUI.m_nID!=(UINT)-1)	// Separator = 0, Popup is -1
    		CmdUI.DoUpdate(pCmdWnd, FALSE);
    }

  5. #5
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Can I send OnUpdateX(CCmdUI* pCmdUI) message

    Hey, you're the man! Thanks!

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