-
June 7th, 2004, 01:09 AM
#1
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"
-
June 7th, 2004, 01:24 AM
#2
in OnUpdateEvent you use
pCmdUI->SetCheck(..);
-
June 7th, 2004, 01:36 AM
#3
Code:
int ind = m_wndToolBar.CommandToIndex(ID_MYCHECKED_BUTTON);
UINT style = m_wndToolBar.GetButtonStyle( ind ) | TBBS_CHECKBOX ;
m_wndToolBar.SetButtonStyle(ind, style );
-
June 7th, 2004, 04:08 AM
#4
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"
-
June 7th, 2004, 04:44 AM
#5
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.
-
June 7th, 2004, 05:36 AM
#6
"There is always something to be happy about"
-
June 7th, 2004, 05:44 AM
#7
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);
}
-
June 7th, 2004, 06:11 AM
#8
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"
-
June 7th, 2004, 06:28 AM
#9
Declare a boolean variable in your class,
add a handler to your menu/toolbar click and toogle the value of boolean there
and in ON_UPDATEUI_XXX hadler just add following
Code:
PCmdUI->SetCheck(bState);
Amit
-
June 7th, 2004, 06:38 AM
#10
Oh Great!!!!!!!!!!
It's Working
Thanks A ton
Sebnak
"There is always something to be happy about"
-
June 8th, 2004, 05:29 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|