Condividi tramite


CHeaderCtrl::Create

Creates a header control and attaches it to a CHeaderCtrl object.

virtual BOOL Create(
   DWORD dwStyle,
   const RECT& rect,
   CWnd* pParentWnd,
   UINT nID 
);

Parameters

  • dwStyle
    Specifies the header control's style. For a description of header control styles, see Header Control Styles in the Windows SDK.

  • rect
    Specifies the header control's size and position. It can be either a CRect object or a RECT structure.

  • pParentWnd
    Specifies the header control's parent window, usually a CDialog. It must not be NULL.

  • nID
    Specifies the header control's ID.

Return Value

Nonzero if initialization was successful; otherwise zero.

Remarks

You construct a CHeaderCtrl object in two steps. First, call the constructor and then call Create, which creates the header control and attaches it to the CHeaderCtrl object.

In addition to the header control styles, you can use the following common control styles to determine how the header control positions and resizes itself (see Common Control Styles for more information):

  • CCS_BOTTOM   Causes the control to position itself at the bottom of the parent window's client area and sets the width to be the same as the parent window's width.

  • CCS_NODIVIDER   Prevents a two-pixel highlight from being drawn at the top of the control.

  • CCS_NOMOVEY   Causes the control to resize and move itself horizontally, but not vertically, in response to a WM_SIZE message. If the CCS_NORESIZE style is used, this style does not apply. Header controls have this style by default.

  • CCS_NOPARENTALIGN   Prevents the control from automatically moving to the top or bottom of the parent window. Instead, the control keeps its position within the parent window despite changes to the size of the parent window. If the CCS_TOP or CCS_BOTTOM style is also used, the height is adjusted to the default, but the position and width remain unchanged.

  • CCS_NORESIZE   Prevents the control from using the default width and height when setting its initial size or a new size. Instead, the control uses the width and height specified in the request for creation or sizing.

  • CCS_TOP   Causes the control to position itself at the top of the parent window's client area and sets the width to be the same as the parent window's width.

You can also apply the following window styles to a header control (see Window Styles for more information):

  • WS_CHILD   Creates a child window. Cannot be used with the WS_POPUP style.

  • WS_VISIBLE   Creates a window that is initially visible.

  • WS_DISABLED   Creates a window that is initially disabled.

  • WS_GROUP   Specifies the first control of a group of controls in which the user can move from one control to the next with the arrow keys. All controls defined with the WS_GROUP style after the first control belong to the same group. The next control with the WS_GROUP style ends the style group and starts the next group (that is, one group ends where the next begins).

  • WS_TABSTOP   Specifies one of any number of controls through which the user can move by using the TAB key. The TAB key moves the user to the next control specified by the WS_TABSTOP style.

If you want to use extended windows styles with your control, call CreateEx instead of Create.

Example

// pParentWnd is a pointer to the parent window.
m_myHeaderCtrl.Create(WS_CHILD | WS_VISIBLE | HDS_HORZ,
   CRect(10, 10, 600, 50), pParentWnd, 1);

Requirements

Header: afxcmn.h

See Also

Reference

CHeaderCtrl Class

Hierarchy Chart

CHeaderCtrl::CHeaderCtrl

Other Resources

CHeaderCtrl Members