I am using CMFCToolbar in a CMFCDesktopAlertDialog which is contained inside a CMFCDesktopAlertWnd. Initially I create the window and insert 3 buttons. Then on some action, I want to change those buttons to 2 or 3 different buttons. I tried using CMFCToolbar::RemoveAllButtons() & then InsertButton(). However, it did not work. When RemoveAllButtons() is called, all button get removed however new buttons are not inserted.
Asked
Active
Viewed 819 times
1
-
If your code doesn't show the desired behavior, it helps if you provide that code, ideally a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – IInspectable May 24 '15 at 22:10
1 Answers
1
This was resolved after calling AdjustLayout after inserting the buttons. The code is as below.
void MyClass::ReplaceButtons()
{
m_m_myMFCToolbar.RemoveAllButtons();
if(condition1)
{
m_myMFCToolbar.InsertButton( CMFCToolBarButton(ID_BUTTON1, 0, _T("MyText1"), FALSE, TRUE ) );
m_myMFCToolbar.InsertButton( CMFCToolBarButton(ID_BUTTON2, 1, _T("MyText2"), FALSE, TRUE ) );
}
else
{
m_myMFCToolbar.InsertButton( CMFCToolBarButton(ID_BUTTON3, 2, _T("MyText3"), FALSE, TRUE ) );
m_myMFCToolbar.InsertButton( CMFCToolBarButton(ID_BUTTON4, 3, _T("MyText4"), FALSE, TRUE) );
}
m_myMFCToolbar.AdjustLayout(); // This was added to resolve the issue
CSize sizeToolBar = m_myMFCToolbar.CalcFixedLayout( FALSE, TRUE );
m_myMFCToolbar.SetWindowPos(NULL, 0, 0, sizeToolBar.cx, sizeToolBar.cy, SWP_NOACTIVATE | SWP_NOZORDER );
}

Ashish
- 53
- 6