Hello,
If you want to enable/disable toolbar buttons, you should use the standard
UPDATE_COMMAND_UI mechanism and write update handlers.
If you want to dynamically switch between different toolbars (with
additional buttons, graphics, etc.) you can use the following function
excerpted from my own "MFC Answer Book":
void EkSwitchBars( CFrameWnd* pFrame,
CControlBar* pBar1,
CControlBar* pBar2,
BOOL bShowBar2,
BOOL bDelay /* = TRUE */ )
{
ASSERT_VALID( pFrame );
ASSERT_VALID( pBar1 );
ASSERT_VALID( pBar2 );
// 1 - Compute "From" and "To" bars
CControlBar* pBarFrom = bShowBar2 ? pBar1 : pBar2;
CControlBar* pBarTo = bShowBar2 ? pBar2 : pBar1;
BOOL bVisible = EkIsBarVisible( pBarFrom );
// 2 - Exchange "From" and "To" window IDs
UINT nIDFrom = ::GetWindowLong( pBarFrom->GetSafeHwnd(), GWL_ID );
UINT nIDTo = ::GetWindowLong( pBarTo->GetSafeHwnd(), GWL_ID );
::SetWindowLong( pBarFrom->GetSafeHwnd(), GWL_ID, nIDTo );
::SetWindowLong( pBarTo->GetSafeHwnd(), GWL_ID, nIDFrom );
// 3 - Hide "From" bar, show "To" bar if "From" bar was visible
pFrame->ShowControlBar( pBarFrom, FALSE, bDelay );
pFrame->ShowControlBar( pBarTo, bVisible, bDelay );
Quote:
}
You will find additional details in FAQ 6.8 of "The MFC Answer Book": How
do I dynamically switch between toolbars? You can find screen shots and a
sample program at
<http://www.mfcfaq.com/mfc_answer_book/contents/faq06-08.htm>.
Find more than 130 similar and advanced tips and techniques in "The MFC
Answer Book: Solutions for Effective Visual C++ Applications". For
additional details, surf to <http://www.mfcfaq.com>.
Good luck!
- Eugene Kain
Author of "The MFC Answer Book: Solutions for Effective Visual C++
Applications" (Addison-Wesley, 1998).
** Browse 150 online pages from the book at <http://www.mfcfaq.com>
** Get the best prices at
<http://www.amazon.com/exec/obidos/ASIN/0201185377/mfcfaqcom>
Quote:
>How would I go about making toolbar buttons unavailable dynamically? when
I
>startup all of the toolbar buttons are available by default. I want to
make
>them available/unavailable at appropriate times. I can't seem to find
this
>in the MSDN so I must just be looking in the wrong place. I created the
>toolbar which contains many buttons.