CMFCCaptionBar Class
A CMFCCaptionBar object is a control bar that can display three elements: a button, a text label, and a bitmap. It can only display one element of each type at a time. You can align each element to the left or right edges of the control or to the center. You can also apply a flat or 3D style to the top and bottom borders of the caption bar.
class CMFCCaptionBar : public CPane
Members
Public Methods
Name |
Description |
---|---|
Creates the caption bar control and attaches it to the CMFCCaptionBar object. |
|
Determines whether another pane can be dynamically inserted between this pane and the parent frame. (Overrides CBasePane::DoesAllowDynInsertBefore.) |
|
Enables or disables the button on the caption bar. |
|
Returns the alignment of the specified element. |
|
Returns the border size of the caption bar. |
|
Retrieves the bounding rectangle of the button on the caption bar. |
|
Returns the distance between the edge of the caption bar elements and the edge of the caption bar control. |
|
Specifies whether the caption bar is in the message bar mode. |
|
Removes the bitmap image from the caption bar. |
|
Removes the button from the caption bar. |
|
Removes the icon from the caption bar. |
|
Removes the text label from the caption bar. |
|
Sets the bitmap image for the caption bar. |
|
Sets the border size of the caption bar. |
|
Sets the button for the caption bar. |
|
Specifies whether the button stays pressed. |
|
Sets the tooltip for the button. |
|
Sets the border style of the caption bar. |
|
Sets the icon for a caption bar. |
|
Sets the tooltip for the image for the caption bar. |
|
Sets the distance between the edge of the caption bar element and the edge of the caption bar control. |
|
Sets the text label for the caption bar. |
Protected Methods
Name |
Description |
---|---|
Called by the framework to fill the background of the caption bar. |
|
Called by the framework to draw the border of the caption bar. |
|
Called by the framework to draw the caption bar button. |
|
Called by the framework to draw the caption bar image. |
|
Called by the framework to draw the caption bar text. |
Data Members
Name |
Description |
---|---|
The background color of the caption bar. |
|
The color of the border of the caption bar. |
|
The color of the caption bar text. |
Remarks
To create a caption bar, follow these steps:
Construct the CMFCCaptionBar object. Typically, you would add the caption bar to a frame window class.
Call the CMFCCaptionBar::Create method to create the caption bar control and attach it to the CMFCCaptionBar object.
Call CMFCCaptionBar::SetButton, CMFCCaptionBar::SetText, CMFCCaptionBar::SetIcon, and CMFCCaptionBar::SetBitmap to set the caption bar elements.
When you set the button element, you must assign a command ID to the button. When the user clicks the button, the caption bar routes the WM_COMMAND messages that have this ID to the parent frame window.
The caption bar can also work in message bar mode, which emulates the message bar that appears in Microsoft Office 2007 applications. In message bar mode, the caption bar displays a bitmap, a message, and a button (which typically opens a dialog box.) You can assign a tooltip to the bitmap.
To enable message bar mode, call CMFCCaptionBar::Create and set the fourth parameter (bIsMessageBarMode) to TRUE.
Example
The following example demonstrates how to use various methods in the CMFCCaptionBar class. The example shows how to create the caption bar control, set a 3D border of the caption bar, set the distance, in pixels, between the edge of the caption bar elements and the edge of the caption bar control, set the button for the caption bar, set the tooltip for the button, set the text label for the caption bar, set the bitmap image for the caption bar, and set the tooltip for the image in the caption bar. This code snippet is part of the MSOffice2007Demo Sample: MFC Office Application.
CMFCCaptionBar m_wndMessageBar;
...
BOOL CMainFrame::CreateMessageBar()
{
// The this pointer points to a CMainFrame class which extends the CFrameWndEx class.
if (!m_wndMessageBar.Create(WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, this, ID_VIEW_MESSAGEBAR, -1, TRUE))
{
TRACE0("Failed to create caption bar\n");
return FALSE;
}
m_wndMessageBar.SetFlatBorder( FALSE );
m_wndMessageBar.SetMargin(10);
m_wndMessageBar.SetButton(_T("Options..."), ID_TOOLS_OPTIONS, CMFCCaptionBar::ALIGN_LEFT, FALSE);
m_wndMessageBar.SetButtonToolTip(_T("Click here to see more options"));
m_wndMessageBar.SetText(_T("Welcome to the MFC MSOffice2007 demonstration!"), CMFCCaptionBar::ALIGN_LEFT);
m_wndMessageBar.SetBitmap(IDB_INFO, RGB(255, 255, 255), FALSE, CMFCCaptionBar::ALIGN_LEFT);
m_wndMessageBar.SetImageToolTip(_T("Important"), _T("Please take a look at MSOffice2007Demo source code to learn how to create advanced user interface in minutes."));
return TRUE;
}
Inheritance Hierarchy
Requirements
Header: afxcaptionbar.h