CToolBar disable/enable buttons
-
One way is to use "command enablers"...
BEGIN_MESSAGE_MAP(CMyFrameWnd, CFrameWnd)
...
ON_UPDATE_COMMAND_UI(ID_BUTTONID, OnUpdateButton)
...
END_MESSAGE_MAP()void CMyFrameWnd::OnUpdateButton(CCmdUI* pCmdUI)
{
if (some_condition)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Mark thanks for reply, but I have dialog based application, there is no ON_UPDATE_COMMAND_UI :(
Then try in OnPaint. if (condition) button->EnableWindow (TRUE); else button->EnableWindow (FALSE); is not the best way, but it will maybe work NOTE: I have not read the article, so im not sure if I'm saying something catastrofical ;) :P
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
-
Mark thanks for reply, but I have dialog based application, there is no ON_UPDATE_COMMAND_UI :(
:doh: Well, anytime after a toolbar is created and the buttons are added to it, you can enable and diable buttons when you need to: // Disable a button m_ToolBar.GetToolBarCtrl().EnableButton(ID_BUTTON1, FALSE); // Enable a button m_ToolBar.GetToolBarCtrl().EnableButton(ID_BUTTON1, TRUE); Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
:doh: Well, anytime after a toolbar is created and the buttons are added to it, you can enable and diable buttons when you need to: // Disable a button m_ToolBar.GetToolBarCtrl().EnableButton(ID_BUTTON1, FALSE); // Enable a button m_ToolBar.GetToolBarCtrl().EnableButton(ID_BUTTON1, TRUE); Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Romiks wrote:
but button was not greyed
Looking at the article, it looks like there's a separate image list for disabled. Are the images in that image list the same as the regular images? You could try omitting the last parameter in the call to LoadTrueColorToolBar() - the system should do its default "greying" for disabled buttons. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Romiks wrote:
but button was not greyed
Looking at the article, it looks like there's a separate image list for disabled. Are the images in that image list the same as the regular images? You could try omitting the last parameter in the call to LoadTrueColorToolBar() - the system should do its default "greying" for disabled buttons. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Mark, many thanks for help. I have tried to omit the last parameter, but it doesn't work :doh:. I will try to use CButton instead of tool bar.
So the buttons diable but they don't look disabled? Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
So the buttons diable but they don't look disabled? Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
I just downloaded the source - I'll take a look. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Ok.. It all works fine in the authors demo app. The author actually omits the last parametr in the call to CTrueColorToolBar::LoadTrueColorToolBar for the RIGHT toolbar. So, the right toolbar shows button bitmaps grayed by the system. For the left toolbar he uses special bitmaps for disabled buttons that don't have any color, just white/black/grays. All the buttons except the first three on left and right are disabled. If you try to disable them yourself they won't look any different :) To enable them, you can add command enablers. For example, there's 9 buttons on the toolbars. I enabled the 7th and 8th buttons like this (in MainFrm.cpp/.h):
// In MainFrm.h
// add these declarations to the CMainFrame class
afx_msg void OnUpdateButton32777(CCmdUI* pCmdUI);
afx_msg void OnUpdateButton32778(CCmdUI* pCmdUI);// In MainFrm.cpp
// add this to CMainFrame message map
ON_UPDATE_COMMAND_UI(ID_BUTTON32777, OnUpdateButton32777)
ON_UPDATE_COMMAND_UI(ID_BUTTON32778, OnUpdateButton32778)// add these handler methods
void CMainFrame::OnUpdateButton32777(CCmdUI* pCmdUI)
{
pCmdUI->Enable(TRUE);
}void CMainFrame::OnUpdateButton32778(CCmdUI* pCmdUI)
{
pCmdUI->Enable(TRUE);
}"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Ok.. It all works fine in the authors demo app. The author actually omits the last parametr in the call to CTrueColorToolBar::LoadTrueColorToolBar for the RIGHT toolbar. So, the right toolbar shows button bitmaps grayed by the system. For the left toolbar he uses special bitmaps for disabled buttons that don't have any color, just white/black/grays. All the buttons except the first three on left and right are disabled. If you try to disable them yourself they won't look any different :) To enable them, you can add command enablers. For example, there's 9 buttons on the toolbars. I enabled the 7th and 8th buttons like this (in MainFrm.cpp/.h):
// In MainFrm.h
// add these declarations to the CMainFrame class
afx_msg void OnUpdateButton32777(CCmdUI* pCmdUI);
afx_msg void OnUpdateButton32778(CCmdUI* pCmdUI);// In MainFrm.cpp
// add this to CMainFrame message map
ON_UPDATE_COMMAND_UI(ID_BUTTON32777, OnUpdateButton32777)
ON_UPDATE_COMMAND_UI(ID_BUTTON32778, OnUpdateButton32778)// add these handler methods
void CMainFrame::OnUpdateButton32777(CCmdUI* pCmdUI)
{
pCmdUI->Enable(TRUE);
}void CMainFrame::OnUpdateButton32778(CCmdUI* pCmdUI)
{
pCmdUI->Enable(TRUE);
}"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Romiks wrote:
I have dialog based MFC application
Oh yeah, I forgot about that, sorry :-O Well I still go back to this: // Disable button ID_BUTTON32777 in m_ToolBar m_ToolBar.GetToolBarCtrl().EnableButton(ID_BUTTON32777, FALSE); // Enable button ID_BUTTON32777 in m_ToolBar m_ToolBar.GetToolBarCtrl().EnableButton(ID_BUTTON32777, TRUE); I'm not sure why that doesn't work for you - I just tested it in a dialog toolbar here. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Romiks wrote:
I have dialog based MFC application
Oh yeah, I forgot about that, sorry :-O Well I still go back to this: // Disable button ID_BUTTON32777 in m_ToolBar m_ToolBar.GetToolBarCtrl().EnableButton(ID_BUTTON32777, FALSE); // Enable button ID_BUTTON32777 in m_ToolBar m_ToolBar.GetToolBarCtrl().EnableButton(ID_BUTTON32777, TRUE); I'm not sure why that doesn't work for you - I just tested it in a dialog toolbar here. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
If you have working dialog based project, could you please send me? my mail:losqut@yandex.ru As for me, buttons are not greyed :(