CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2001
    Location
    New Delhi,India
    Posts
    51

    Angry Toggle Toolbar Buttons

    Kindly provide me with the code/logic
    that how to toggle the buttons on the toolbar
    i.e if u press it once it must be shown as pressed and when u press it once again it should be shown as up


    Kindly Help

    Sebnak
    "There is always something to be happy about"

  2. #2
    Join Date
    Dec 2000
    Location
    Greece, Athens
    Posts
    219
    in OnUpdateEvent you use

    pCmdUI->SetCheck(..);

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398
    Code:
    	int ind = m_wndToolBar.CommandToIndex(ID_MYCHECKED_BUTTON); 
    	UINT style = m_wndToolBar.GetButtonStyle( ind ) | TBBS_CHECKBOX ;
    	m_wndToolBar.SetButtonStyle(ind, style );

  4. #4
    Join Date
    Mar 2001
    Location
    New Delhi,India
    Posts
    51
    Thanks for the reply , now the same Functionality I have to add in the menu for those buttons,i.e if button A is checked in menu List , in front of menu item a , a chek mark must mbe there,
    It is possible if both share the same id
    now For setting chek I am using PcmDUI->Setcheck();
    But As I have wriiten this in on_update,
    the toggling starts on and off ,i.e there is no need to explicitly push the button
    kindly help
    "There is always something to be happy about"

  5. #5
    Join Date
    Dec 2000
    Location
    Greece, Athens
    Posts
    219
    Create a menu item, and give it the same resource id as for the toolbar button. Also check the 'Checked' property in the menu item.

  6. #6
    Join Date
    Mar 2001
    Location
    New Delhi,India
    Posts
    51
    It's not working
    "There is always something to be happy about"

  7. #7
    Join Date
    Feb 2002
    Posts
    3,788
    Originally posted by sebnak
    Thanks for the reply , now the same Functionality I have to add in the menu for those buttons,i.e if button A is checked in menu List , in front of menu item a , a chek mark must mbe there,
    It is possible if both share the same id
    now For setting chek I am using PcmDUI->Setcheck();
    But As I have wriiten this in on_update,
    the toggling starts on and off ,i.e there is no need to explicitly push the button
    kindly help
    i simply cannot follow you. please try to explain the problem better.
    to check/uncheck a menu item use:
    Code:
    void CMainFrame::OnUpdateMenuItem(CCmdUI* pCmdUI) 
    {
    	// TODO: Add your command update UI handler code here
    	pCmdUI->SetCheck(TRUE/FALSE);
    }

  8. #8
    Join Date
    Mar 2001
    Location
    New Delhi,India
    Posts
    51
    there is a button on the toolbar , which do something and toggles, the same work is to be done by a menuitem from the main menu
    Now for toggling on Update_command, I have used the above code i.e getButtonStyle and SetButtonStlye
    Now the menuitem on menu shares the same id as of button and has the property of checked,now if the button is toggling , simultansly the menu item should bear a check or unchek mark

    If I used PCCmd->SetCheck, this is only for handling toolbar buttons as the pointer has the value for CtoolbarCmdUI , and not the value for Cmenu,
    So it changes the button value and not the menu item(check , uncheck), though the Id's are Same

    for eg
    int ind = m_wndToolBar.CommandToIndex(ID_OPTIONS_BAVIEW);
    UINT style = m_wndToolBar.GetButtonStyle( ind ) | TBBS_CHECKBOX ;
    m_wndToolBar.SetButtonStyle(ind, style );
    if(style == 2)
    {
    PCmdUI->SetCheck(True)
    }
    I am not able to control my menu item chek , unchek , while the button toggles

    this is the prob
    I hope now u r having the clear picture
    Kindly Help
    "There is always something to be happy about"

  9. #9
    Join Date
    Jan 2004
    Location
    Punjab, India
    Posts
    113
    Declare a boolean variable in your class,
    Code:
    BOOL bState;
    add a handler to your menu/toolbar click and toogle the value of boolean there
    Code:
    bState = !bState;
    and in ON_UPDATEUI_XXX hadler just add following
    Code:
    PCmdUI->SetCheck(bState);
    Amit

  10. #10
    Join Date
    Mar 2001
    Location
    New Delhi,India
    Posts
    51
    Oh Great!!!!!!!!!!

    It's Working

    Thanks A ton

    Sebnak
    "There is always something to be happy about"

  11. #11
    Join Date
    Mar 2001
    Location
    New Delhi,India
    Posts
    51
    hi Amit

    but sometimes it's not working
    I mean if u have pressed the button down , there is correponding check mark agnst the menu item, vice versa , if u pressed the button up, then again the menu item gets unchek, but if u r doing it frequently , despite u have unpressed the button , a chek mark will be there , i.e the status is not updated b/w the Command handler and the Update_ handler
    how could we overcome this problem, I don't want to incorporate
    Sleep etc

    I hope this is the problem or probably there can be another reason for this .

    Kindly suggest
    Sebnak
    "There is always something to be happy about"

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