Condividi tramite


CTreeCtrl::Create

If you specify the tree control in a dialog box template, or if you are using CTreeView, your tree control is created automatically when the dialog box or view is created.

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

Parameters

  • dwStyle
    Specifies the tree view control's style. Apply window styles, described in CreateWindow, and any combination of tree view control styles as described in the Windows SDK.

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

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

  • nID
    Specifies the tree view control's ID.

Return Value

Nonzero if initialization was successful; otherwise 0.

Remarks

If you want to create the tree control as a child window of some other window, use the Create member function. If you create the tree control using Create, you must pass it WS_VISIBLE, in addition to other tree view styles.

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

To create a tree control with extended window styles, call CreateEx instead of Create.

Example

// Assuming your window has a CTreeCtrl member named m_TreeCtrl,
// you can create the tree control window with a child ID of ID_MYTREE
// using a call like this:

m_TreeCtrl.Create(WS_VISIBLE | WS_TABSTOP | WS_CHILD | WS_BORDER
   | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_HASLINES
   | TVS_DISABLEDRAGDROP | TVS_NOTOOLTIPS | TVS_EDITLABELS,
   CRect(10, 10, 300, 100), this, ID_MYTREE);

// The control will have the appropiate window styles, and the tree
// control styles specified are those most commonly used.

Requirements

Header: afxcmn.h

See Also

Reference

CTreeCtrl Class

Hierarchy Chart

CTreeCtrl::CTreeCtrl

Other Resources

CTreeCtrl Members