CMFCHeaderCtrl 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 CMFCHeaderCtrl Class.

The CMFCHeaderCtrl class supports sorting multiple columns in a header control.

class CMFCHeaderCtrl : public CHeaderCtrl  

Public Constructors

NameDescription
CMFCHeaderCtrl::CMFCHeaderCtrlConstructs a CMFCHeaderCtrl object.
CMFCHeaderCtrl::~CMFCHeaderCtrlDestructor.

Public Methods

NameDescription
CMFCHeaderCtrl::EnableMultipleSortEnables or disables multiple column sort mode for the current header control.
CMFCHeaderCtrl::GetColumnStateIndicates whether a column is not sorted, or is sorted in ascending or descending order.
CMFCHeaderCtrl::GetSortColumnRetrieves the zero-based index of the first sorted column in the header control.
CMFCHeaderCtrl::GetThisClassUsed by the framework to obtain a pointer to the CRuntimeClass object that is associated with this class type.
CMFCHeaderCtrl::IsAscendingIndicates whether any column in the header control is sorted in ascending order.
CMFCHeaderCtrl::IsDialogControlIndicates whether the parent window of the current header control is a dialog box.
CMFCHeaderCtrl::IsMultipleSortIndicates whether the current header control is in multiple column sort mode.
CMFCHeaderCtrl::RemoveSortColumnRemoves the specified column from the list of sort columns.
CMFCHeaderCtrl::SetSortColumnSets the sort order of a specified column in a header control.

Protected Methods

NameDescription
CMFCHeaderCtrl::OnDrawItemCalled by the framework to draw a header control column.
CMFCHeaderCtrl::OnDrawSortArrowCalled by the framework to draw the sort arrow.
CMFCHeaderCtrl::OnFillBackgroundCalled by the framework to fill the background of a header control column.

The following example demonstrates how to construct an object of the CMFCHeaderCtrl class, and how to enable multiple column sort mode for the current header control.

	CMFCHeaderCtrl* headerCtrl = new CMFCHeaderCtrl();
	headerCtrl->EnableMultipleSort();

The CMFCHeaderCtrl class draws a sort arrow on a header control column to indicate that the column is sorted. Use multiple column sort mode if a set of columns in the parent list control ( CMFCListCtrl Class) can be sorted at the same time.

CObject

CCmdTarget

CWnd

CHeaderCtrl

CMFCHeaderCtrl

Header: afxheaderctrl.h

Constructs a CMFCHeaderCtrl object.

CMFCHeaderCtrl::CMFCHeaderCtrl()  

Remarks

This constructor initializes the following member variables to the specified values:

Member variableValue
m_bIsMousePressedFALSE
m_bMultipleSortFALSE
m_bAscendingTRUE
m_nHighlightedItem-1
m_bTrackedFALSE
m_bIsDlgControlFALSE
m_hFontNULL

Enables or disables multiple column sort mode for the current header control.

void EnableMultipleSort(BOOL bEnable=TRUE);

Parameters

[in] bEnable
TRUE to enable multiple column sort mode; FALSE to disable multiple column sort mode and to remove any columns from the list of sorted columns. The default value is TRUE.

Remarks

Use this method to enable or disable multiple column sort mode. Two or more columns can participate in a sort if the header control is in multiple column sort mode.

Indicates whether a column is unsorted, or is sorted in ascending or descending order.

int GetColumnState(int iColumn) const;  

Parameters

[in] iColumn
The zero-based index of a column.

Return Value

A value that indicate the sort status of the specified column. The following table lists the possible values:

ValueDescription
-1Sorted in descending order.
0Not sorted.
1Sorted in ascending order.

Remarks

Retrieves the zero-based index of the first sorted column in the header control.

int GetSortColumn() const;  

Return Value

The index of a sorted column, or -1 if no sorted column is found.

Remarks

If the header control is in multiple column sort mode and you compiled the application in debug mode, this method asserts and advises you to use the CMFCHeaderCtrl::GetColumnState method instead. If the header control is in multiple column sort mode and you compiled the application in retail mode, this method returns -1.

Indicates whether any column in the header control is sorted in ascending order.

BOOL IsAscending() const;  

Return Value

TRUE if any column in the header control is sorted in ascending order; otherwise, FALSE.

Remarks

The value that this method returns is used to display the appropriate sort arrow on the header control item. Use the CMFCHeaderCtrl::SetSortColumn method to set the sort order.

Indicates whether the parent window of the current header control is a dialog box.

BOOL IsDialogControl() const;  

Return Value

TRUE if the parent window of the current header control is a dialog box; otherwise, FALSE.

Indicates whether the current header control is in multiple column sort mode.

BOOL IsMultipleSort() const;  

Return Value

TRUE if multiple column sort mode is enabled; otherwise, FALSE.

Remarks

Use the CMFCHeaderCtrl::EnableMultipleSort method to enable or disable multiple column sort mode. Two or more columns can participate in a sort if the header control is in multiple column sort mode.

Called by the framework to draw a header control column.

virtual void OnDrawItem(
    CDC* pDC,  
    int iItem,  
    CRect rect,  
    BOOL bIsPressed,  
    BOOL bIsHighlighted);

Parameters

[in] pDC
A pointer to a device context.

[in] iItem
The zero-based index of the item to draw.

[in] rect
The bounding rectangle of the item to draw.

[in] bIsPressed
TRUE to draw the item in pressed state; otherwise, FALSE.

[in] bIsHighlighted
TRUE to draw the item in highlighted state; otherwise, FALSE.

Called by the framework to draw the sort arrow.

virtual void OnDrawSortArrow(
    CDC* pDC,  
    CRect rectArrow);

Parameters

[in] pDC
A pointer to a device context.

[in] rectArrow
The bounding rectangle of the sort arrow.

Called by the framework to fill the background of a header control column.

virtual void OnFillBackground(CDC* pDC);

Parameters

[in] pDC
A pointer to a device context.

Remarks

Removes the specified column from the list of sort columns.

void RemoveSortColumn(int iColumn);

Parameters

[in] iColumn
The zero-based index of the column to remove.

Sets the sort order of a specified column in a header control.

void SetSortColumn(
    int iColumn,  
    BOOL bAscending=TRUE,  
    BOOL bAdd=FALSE);

Parameters

[in] iColumn
The zero-based index of a header control column. If this parameter is less than zero, this method removes all columns from the list of sort columns.

[in] bAscending
Specifies the sort order of the column that the iColumn parameter specifies. TRUE to set ascending order; FALSE to set descending order. The default value is TRUE.

[in] bAdd
TRUE to set the sort order of the column that the iColumn parameter specifies.

If the current header control is in multiple column sort mode, this method adds the specified column to the list of sort columns. Use CMFCHeaderCtrl::EnableMultipleSort to set multiple column sort mode.

If multiple column sort mode is not set and this method is compiled in debug mode, this method asserts. If multiple column sort mode is not set and this method is compiled in retail mode, this method first removes all columns from the list of sort columns, and then adds the specified column to the list.

FALSE to first remove all columns from the list of sort columns, and then add the specified column to the list. The default value is FALSE.

Remarks

Use this method to set the sort order of a column. If necessary, this method adds the column to the list of sort columns. The header control uses the sort order to draw a sort arrow that points up or down.

Hierarchy Chart
Classes
CMFCListCtrl Class

Show: