Internet Explorer 3.0 introduced a new control type to Windows: the rebar control. A rebar is a container for other controls. You populate a rebar control by adding bands to it; each band can include a child window such as a toolbar, push button, or combo box. You can add as many bands as you like, and once the rebar is displayed, the user can move and resize the bands to configure the rebar control to his or her liking. Each band in a rebar can optionally have an image from an image list, a label (text string), and a bitmap associated with it. The image and label, if used, are displayed on the face of the band. The bitmap, if used, is tiled horizontally and vertically to form a stylized background for whatever else happens to be displayed in the band. Remember the toolbar with the textured background in Internet Explorer 3.0? That toolbar was actually a rebar control wrapped around an otherwise rather ordinary toolbar control. A bitmap provided the textured background.
MFC 6.0 introduced two new classes to simplify the programming of rebar controls: CReBar and CReBarCtrl. CReBarCtrl is a low-level class that provides a very thin wrapper around a raw rebar control. CReBar is a high-level class that makes it almost as easy to add rebars to an MFC application as it is to add toolbars and status bars. CReBar publishes just three member functions:
With CReBar and its member functions to help out, creating rebar-type toolbars like the ones used in Visual C++ could hardly be easier. The following example converts an MFC toolbar into a rebar by first creating a CToolBar and then making it a band in a CReBar:
m_wndToolBar.CreateEx (this); m_wndToolBar.LoadToolBar (IDR_TOOLBAR); m_wndReBar.Create (this); m_wndReBar.AddBar (&m_wndToolBar);
You can use AddBar's optional second and third parameters to specify a label and a background bitmap. For example, if m_bitmap is a CBitmap object, the statements
m_bitmap.LoadBitmap (IDB_BKGND); m_wndToolBar.CreateEx (this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT); m_wndToolBar.LoadToolBar (IDR_TOOLBAR); m_wndReBar.Create (this); m_wndReBar.AddBar (&m_wndToolBar, _T ("Main"), &m_bitmap);
assign the toolbar the label "Main" and use the bitmap resource whose ID is IDB_BKGND as the toolbar's background. When you use a background bitmap in this manner, it's important to create the toolbar with the styles TBSTYLE_FLAT and TBSTYLE_TRANSPARENT and to use light gray as the toolbar buttons' background color. Otherwise, the button backgrounds are drawn over the top of the background bitmap, and you won't get the effect you were hoping for.
If you check the Internet Explorer ReBars box in AppWizard's Step 4 dialog box (shown in Figure 12-10), AppWizard wraps a rebar around the toolbar that it generates. If you want to do more with the rebar, such as add a label or a bitmap, or if your application features multiple toolbars and you want to wrap each of them in a rebar, you must add the code yourself.
Figure 12-10. Using AppWizard to wrap a rebar around a toolbar.
|The CHM file was converted to HTML by chm2web software.|