CMFCCaptionButton Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CMFCCaptionButton Class.

The CMFCCaptionButton class implements a button that is displayed on the caption bar for a docking pane or a mini-frame window. Typically, the framework creates caption buttons automatically.

class CMFCCaptionButton : public CObject  

Constructors

NameDescription
CMFCCaptionButton::CMFCCaptionButtonConstructs a CMFCCaptionButton object.

Public Methods

NameDescription
CMFCCaptionButton::GetHitReturns the command represented by the button.
CMFCCaptionButton::GetIconIDReturns the image ID associated with the button.
CMFCCaptionButton::GetRectReturns the rectangle occupied by the button.
CMFCCaptionButton::GetSizeReturns the width and height of the button.
CMFCCaptionButton::IsMiniFrameButtonIndicates whether the title bar height is set to mini size.
CMFCCaptionButton::MoveSets the button draw location and window show state.
CMFCCaptionButton::OnDrawDraws the caption button.
CMFCCaptionButton::SetMiniFrameButtonSets the mini size of the title bar.

You can derive a class from CPaneFrameWnd Class and use the protected method, AddButton, to add caption buttons to a mini frame window.

CPaneFrameWnd.h defines command IDs for two types of caption buttons:

  • AFX_CAPTION_BTN_PIN, which displays a pin button when the docking pane supports auto-hide mode.

  • AFX_CAPTION_BTN_CLOSE, which displays a Close button when the pane can be closed or hidden.

The following example demonstrates how to construct a CMFCCaptionButton object and set the mini size of the title bar.

	CMFCCaptionButton* captionButton = new CMFCCaptionButton(AFX_HTCLOSE);
	captionButton->SetMiniFrameButton(true);

CObject

CMFCCaptionButton

Header: afxcaptionbutton.h

Constructs a CMFCCaptionButton object.

CMFCCaptionButton();

 
CMFCCaptionButton(
    UINT nHit,  
    BOOL bLeftAlign = FALSE);

Parameters

[in] nHit
The command associated with the button.

[in] bLeftAlign
Specifies whether the button is aligned to the left.

The following table lists possible values for the nHit parameter.

ValueCommand
AFX_HTCLOSEClose button.
HTMINBUTTONMinimize button.
HTMAXBUTTONMaximize button.
AFX_HTLEFTBUTTONLeft arrow button.
AFX_HTRIGHTBUTTONRight arrow button.
AFX_HTMENUDown arrow menu button.
HTNOWHEREThe default value; represents no command.

Remarks

By default, caption buttons are not associated with a command.

Caption buttons are aligned either on the right or left.

Returns the command represented by the button.

UINT GetHit() const;  

Return Value

The command represented by the button.

The following table lists possible return values.

ValueCommand
AFX_HTCLOSEClose button.
HTMINBUTTONMinimize button.
HTMAXBUTTONMaximize button.
AFX_HTLEFTBUTTONLeft arrow button.
AFX_HTRIGHTBUTTONRight arrow button.
AFX_HTMENUDown arrow menu button.
HTNOWHEREThe default value; represents no command.

Returns the image ID associated with the button.

virtual CMenuImages::IMAGES_IDS GetIconID(
    BOOL bHorz,  
    BOOL bMaximized = FALSE) const;  

Parameters

[in] bHorz
TRUE for left or right arrow image IDs; FALSE for up or down arrow image IDs.

[in] bMaximized
TRUE for a maximize image ID; FALSE for a minimize image ID.

Return Value

The image ID.

Remarks

The parameters specify image IDs for minimize or maximize caption buttons.

Returns the rectangle occupied by the button.

virtual CRect GetRect() const;  

Return Value

The rectangle that represents the location of the button.

Remarks

If you cannot see the button, the size returned is 0.

Returns the width and height of the button.

static CSize GetSize();

Return Value

The outer dimensions of the button.

Remarks

The size returned includes button margin and border.

Indicates whether the title bar height is set to mini size.

BOOL IsMiniFrameButton() const;  

Return Value

TRUE if the caption is set to mini size; otherwise FALSE.

Remarks

Sets the button draw location and window show state.

void Move(
    const CPoint& ptTo,  
    BOOL bHide = FALSE);

Parameters

[in] ptTo
The new location.

[in] bHide
Whether to show the button.

Draws the caption button.

virtual void OnDraw(
    CDC* pDC,  
    BOOL bActive,  
    BOOL bHorz = TRUE,  
    BOOL bMaximized = TRUE,  
    BOOL bDisabled = FALSE);

Parameters

[in] pDC
Pointer to a device context for the button.

[in] bActive
Whether to draw an active button image.

[in] bHorz
Reserved for use in a derived class.

[in] bMaximized
Whether to draw a maximized button image.

[in] bDisabled
Whether to draw an enabled button image.

Remarks

The bMaximized parameter is used when the button is a maximize or minimize button.

Sets the mini size of the title bar.

void SetMiniFramebutton(BOOL bSet = TRUE);

Parameters

[in] bSet
TRUE for mini title bar height; FALSE for default title bar height.

Hierarchy Chart
Classes
CPaneFrameWnd Class
CDockablePane Class

Show: