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

    [q] the difference between ON_COMMAND_EX and ON_UPDATE_COMMAND_UI

    to the mfc gurus,

    except for the obvious prototypes and function declaration difference
    between the two:

    // UPDATE_COMMAND_UI
    void CMainFrame::OnMyUpdateCommandUI(CCmdUI* pCmdUI)
    {
    // some code
    }
    //ON_COMMAND_EX
    void CMainFrame::OnMyCommandEX(UINT nID)
    {
    // some code
    }




    why can't the pointer to CCmdUI* pCmdUI be easly got inside of the
    ON_COMMAND_EX handler (if so how)? I want to be able to enable or
    disable a toolbar button from the ON_COMMAND_EX handler but no one
    seems to know the ON_COMMAND_EX handler but I'm quite sure it can be
    done (can it)? there is very little verbiage on ON_COMMAND_EX! and I
    would like to know the proper usage of both of them.

    all help will be greatly appreciated
    michael b. williams



  2. #2
    Join Date
    Aug 1999
    Location
    CA
    Posts
    23

    Re: [q] the difference between ON_COMMAND_EX and ON_UPDATE_COMMAND_UI

    ON_COMMAND_EX essentially allows you to completely take over what MFC is doing -- you can return TRUE to indicate that the command has been handled, otherwise routing will continue to other command target objects.

    The OnMyUpdateCommandUI(CCmdUI* pCmdUI) on the other hand is a quick way to enable controls (the documentation shows that it can do buttons, check boxes...) in control bars during idle (CWindApp::OnIdle) processing.


  3. #3
    Join Date
    Aug 1999
    Posts
    55

    Re: [q] the difference between ON_COMMAND_EX and ON_UPDATE_COMMAND_UI

    mbw4359 wrote

    why can't the pointer to CCmdUI* pCmdUI be easly got inside of the
    ON_COMMAND_EX handler (if so how)? I want to be able to enable or
    disable a toolbar button from the ON_COMMAND_EX handler but no one
    seems to know the ON_COMMAND_EX handler but I'm quite sure it can be
    done (can it)? there is very little verbiage on ON_COMMAND_EX! and I
    would like to know the proper usage of both of them.


    but what about the question about the CmdUI* pCmdUI? How do I initialize it so that I can call


    // ON_COMMAND_EX handler
    void CMainFrame::OnMyCommandEX(UINT UID)
    {
    CmdUI* pCmdUI = ???????????????????; // to intialize it pointing to the button on my toolbar
    pCmdU->Enable(TRUE);
    // or
    pCmdU->Enable(FALSE);
    }






  4. #4
    Join Date
    May 1999
    Location
    CA, USA
    Posts
    586

    Re: [q] the difference between ON_COMMAND_EX and ON_UPDATE_COMMAND_UI

    If you do a search through the MFC src code for ON_COMMAND_EX there are quite a few examples where you can see how MS use this function... One instance which appears to be close to what you want to do is in Winfrm.cpp:

    BEGIN_MESSAGE_MAP(CFrameWnd, CWnd)
    //{{AFX_MSG_MAP(CFrameWnd)
    :
    ON_COMMAND_EX(ID_VIEW_STATUS_BAR, OnBarCheck)
    :
    //}}AFX_MSG_MAP

    BOOL CFrameWnd::OnBarCheck(UINT nID)
    {
    ASSERT(ID_VIEW_STATUS_BAR == AFX_IDW_STATUS_BAR);
    ASSERT(ID_VIEW_TOOLBAR == AFX_IDW_TOOLBAR);

    CControlBar* pBar = GetControlBar(nID);
    if (pBar != NULL)
    {
    ShowControlBar(pBar, (pBar->GetStyle() & WS_VISIBLE) == 0, FALSE);
    return TRUE;
    }
    return FALSE;
    }


    Rail

    ------------
    Recording Engineer/Software Developer
    Rail Jon Rogut Software
    http://home.earthlink.net/~railro/
    railro@earthlink.net

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