แก้ไข

แชร์ผ่าน


CReBar Class

A control bar that provides layout, persistence, and state information for rebar controls.

Syntax

class CReBar : public CControlBar

Members

Public Methods

Name Description
CReBar::AddBar Adds a band to a rebar.
CReBar::Create Creates the rebar control and attaches it to the CReBar object.
CReBar::GetReBarCtrl Allows direct access to the underlying common control.

Remarks

A rebar object can contain a variety of child windows, usually other controls, including edit boxes, toolbars, and list boxes. A rebar object can display its child windows over a specified bitmap. Your application can automatically resize the rebar, or the user can manually resize the rebar by clicking or dragging its gripper bar.

Example of RebarMenu.

Rebar Control

A rebar object behaves similarly to a toolbar object. A rebar uses the click-and-drag mechanism to resize its bands. A rebar control can contain one or more bands, with each band having any combination of a gripper bar, a bitmap, a text label, and a child window. However, bands cannot contain more than one child window.

CReBar uses the CReBarCtrl class to provide its implementation. You can access the rebar control through GetReBarCtrl to take advantage of the control's customization options. For more information about rebar controls, see CReBarCtrl. For more information about using rebar controls, see Using CReBarCtrl.

Caution

Rebar and rebar control objects do not support MFC control bar docking. If CRebar::EnableDocking is called, your application will assert.

Inheritance Hierarchy

CObject

CCmdTarget

CWnd

CControlBar

CReBar

Requirements

Header: afxext.h

CReBar::AddBar

Call this member function to add a band to the rebar.

BOOL AddBar(
    CWnd* pBar,
    LPCTSTR pszText = NULL,
    CBitmap* pbmp = NULL,
    DWORD dwStyle = RBBS_GRIPPERALWAYS | RBBS_FIXEDBMP);

BOOL AddBar(
    CWnd* pBar,
    COLORREF clrFore,
    COLORREF clrBack,
    LPCTSTR pszText = NULL,
    DWORD dwStyle = RBBS_GRIPPERALWAYS);

Parameters

pBar
A pointer to a CWnd object that is the child window to be inserted into the rebar. The referenced object must have a WS_CHILD.

lpszText
A pointer to a string containing the text to appear on the rebar. NULL by default. The text contained in lpszText is not part of the child window; it is on the rebar itself.

pbmp
A pointer to a CBitmap object to be displayed on the rebar background. NULL by default.

dwStyle
A DWORD containing the style to apply to the rebar. See the fStyle function description in the Win32 structure REBARBANDINFO for a complete list of band styles.

clrFore
A COLORREF value that represents the foreground color of the rebar.

clrBack
A COLORREF value that represents the background color of the rebar.

Return Value

Nonzero if successful; otherwise 0.

Example

// Define a CRebar in your class definition,
// such as: CReBar m_wndReBar;
m_wndReBar.Create(this);
m_wndDlgBar.Create(this, IDD_DIALOGBAR, CBRS_ALIGN_TOP,
                   IDD_DIALOGBAR);
m_wndReBar.AddBar(&m_wndDlgBar);

CReBar::Create

Call this member function to create a rebar.

virtual BOOL Create(
    CWnd* pParentWnd,
    DWORD dwCtrlStyle = RBS_BANDBORDERS,
    DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_TOP,
    UINT nID = AFX_IDW_REBAR);

Parameters

pParentWnd
Pointer to the CWnd object whose Windows window is the parent of the status bar. Normally your frame window.

dwCtrlStyle
The rebar control style. By default, RBS_BANDBORDERS, which displays narrow lines to separate adjacent bands within the rebar control. See Rebar Control Styles in the Windows SDK for a list of styles.

dwStyle
The rebar window styles.

nID
The rebar's child-window ID.

Return Value

Nonzero if successful; otherwise 0.

Example

See the example for CReBar::AddBar.

CReBar::GetReBarCtrl

This member function allows direct access to the underlying common control.

CReBarCtrl& GetReBarCtrl() const;

Return Value

A reference to a CReBarCtrl object.

Remarks

Call this member function to take advantage of the functionality of the Windows rebar common control in customizing your rebar. When you call GetReBarCtrl, it returns a reference object to the CReBarCtrl object so you can use either set of member functions.

For more information about using CReBarCtrl to customize your rebar, see Using CReBarCtrl.

Example

CReBarCtrl &refReBarCtrl = m_wndReBar.GetReBarCtrl();

UINT nBandCount = refReBarCtrl.GetBandCount();
CString msg;
msg.Format(_T("Band Count is: %u"), nBandCount);
AfxMessageBox(msg);

See also

MFC Sample MFCIE
CControlBar Class
Hierarchy Chart