CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2002
    Posts
    60

    Command (Toolbar button) update handler does not get called

    Hi,
    I've got a command update handler which does the work and update my toolbar button, but... not all the time... !?

    Does this handler called every time the application is on idle?

    I have a situation where my button should get enabled but the handler doesn't even get called afterwards. Any ideas why?

    Is it O.K., in addition to the command update handler, to directly go and update the toolbar button?

    Thanks.

  2. #2
    Join Date
    May 2001
    Location
    Beijing, China
    Posts
    234
    Normally, the toolbar button is related to the menu, so the update handle for menu can change the status of button too,

    but you also can add the update handle for tool bar button, and this function, I think, is called each time when the button need to be displayed.

  3. #3
    Join Date
    Feb 2002
    Posts
    60
    Can I cause the handler to get called?

  4. #4
    Join Date
    May 2001
    Location
    Beijing, China
    Posts
    234
    Sorry, something wrong in my previous reply, It should be

    When the toolbar need to be displayed and when the condition is changed, the handler function will be called,

    for example, if your handler like this:

    void CView::OnUpdateEdit(CCmdUI* pCmdUI)
    {
    UINT m_sel = (UINT) Get();

    if (m_sel > 0)
    pCmdUI->Enable(TRUE);
    else
    pCmdUI->Enable(FALSE);
    }

    and then, if m_sel size is changed, the button status will change too.

  5. #5
    Join Date
    Feb 2002
    Posts
    60
    Hi,
    In my case the condition got changed but the handler doesn't get called after the change - so I would like to force him to get called.
    It seems that call the handler directly (which CCmdUi to pass?) is wrong, so how do I make the framework to call it?

  6. #6
    Join Date
    Feb 2002
    Posts
    60
    O.K.
    My problem got solved, when I moved the command handler and command update handler to the main frame class.

  7. #7
    Join Date
    Apr 2003
    Location
    Athens, Greece
    Posts
    1,094
    Hi,
    Are you sure that the OnCmdUI() is not called? This is called all the time in my application. Have you tried putting a brkpoint in there (after the app starts running or else you will not be able to interact with it!) ?
    I do not think the solution is to explicitly call the handler.
    If it really is not called can you show some code?
    Extreme situations require extreme measures

  8. #8
    Join Date
    Feb 2002
    Posts
    60
    Well,
    There is no much to show.
    The command update handler is:
    void CMainFrame::OnUpdateObjectDelete(CCmdUI* pCmdUI)
    {
    pCmdUI->Enable( b_existing_object && b_removable_item );
    }

  9. #9
    Join Date
    Jul 2003
    Location
    Linz,Austria
    Posts
    48
    hi Haim B,

    you've found the problem by your own: the handlers have to be in the mainframe class anyway, it doesn't work properly in any other class ( like CView and for sure not in a CDocument )

    greetings and blue skies

  10. #10
    Join Date
    May 2001
    Location
    Beijing, China
    Posts
    234
    Hi, Tomcat101:

    I do have some projects which has handler in CView and CDoc.

    So I can't agree what you said.

  11. #11
    Join Date
    Jul 2003
    Location
    Linz,Austria
    Posts
    48
    hi,

    yes, i know that they're working in this classes too, but for me it makes no sense because normally ( in every project that i made till now ) the toolbar is part of the mainframe and when i need to update them i make this in relation to the current used CDoc or CView.
    the second reason why i make my updates in the mainframe is that the handler of the standard-buttons like 'NewFile', 'OpenFile' and so on are in the mainframe-class too and i like to have them on one place, so if i have to make changes i know where to search;

    but for sure you're right that it is functional in all this classes, too.

    greetings and blue skies

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