Toolbar at runtime 
Author Message
 Toolbar at runtime

Hello,

I need to create a toolbar with a bitmap specified at run time.
How would I do that?

Thanks,
Svetlana



Mon, 09 Jul 2001 03:00:00 GMT  
 Toolbar at runtime
You can do it like this:

1. CToolBarCtrl& tb = m_wndToolBar.GetToolBarCtrl();
tb.SetImageList(...);

OR

2. You could also call CToolBar::SetBitmap() to set bitmap.

--
Ajay Kalra

Quote:

>Hello,

>I need to create a toolbar with a bitmap specified at run time.
>How would I do that?

>Thanks,
>Svetlana




Mon, 09 Jul 2001 03:00:00 GMT  
 Toolbar at runtime
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.


Fri, 13 Jul 2001 03:00:00 GMT  
 Toolbar at runtime
Hello,

If you only want to enable/disable the toolbar buttons, you should use the
standard UPDATE_COMMAND_UI mechanism.
If you want to dynamically change the toolbar itself (to have additional
buttons...) you can use the following function to switch between 2
toolbars:

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:
}

The above code can easily be generalized to switch between more than 2
toolbars.

You will find additional details in FAQ 6.8 of "The MFC Answer Book": How
do I dynamically switch between different 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.



Sat, 14 Jul 2001 03:00:00 GMT  
 Toolbar at runtime
Hello,

If you only want to enable/disable the toolbar buttons, you should use the
standard UPDATE_COMMAND_UI mechanism.
If you want to dynamically change the toolbar itself (to have additional
buttons...) you can use the following function to switch between 2
toolbars:

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:
}

The above code can easily be generalized to switch between more than 2
toolbars.

You will find additional details in FAQ 6.8 of "The MFC Answer Book": How
do I dynamically switch between different 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.



Sat, 14 Jul 2001 03:00:00 GMT  
 Toolbar at runtime
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.



Sat, 14 Jul 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Customizing Toolbars (at runtime) sample code

2. Changing Floating Toolbar Caption Runtime...

3. Adding button to the toolbar at runtime?

4. Change Toolbar runtime

5. Runtime Toolbar Creation

6. Addbitmap into Toolbar bitmap at runtime

7. Invisible at Runtime or Not Invisible at Runtime ?

8. Microsoft Visual C++ Runtime Library Runtime Error When Browsing in IE6

9. Microsoft Visual C++ Runtime Library Runtime Error When Browsing in IE6

10. Toolbar into another Toolbar?

11. Toolbar button shows up after toolbar is moved????

12. Toolbars in toolbars

 

 
Powered by phpBB® Forum Software