Condividi tramite


CTreeCtrl::GetItemPartRect

Retrieves the bounding rectangle for a specified part of a specified item in the current tree-view control.

BOOL GetItemPartRect(
     HTREEITEM hItem, 
     int nPart, 
     LPRECT lpRect
)const;

Parameters

Parameter

Description

[in] hItem

Handle to a tree-view control item.

[in] nPart

Identifier for the part. Must be set to TVGIPR_BUTTON.

[out] lpRect

Pointer to a RECT structure. If this method is successful, the structure receives the rectangle coordinates of the part specified by hItem and nPart.

Return Value

true if this method is successful; otherwise, false.

Remarks

Each tree control item is bounded by a graphics rectangle. Whenever a point in that rectangle is clicked, the item is said to be hit. This method returns the largest rectangle such that when a point in the rectangle is clicked, the item identified by the hItem parameter is hit.

This method sends the TVM_GETITEMPARTRECT message, which is described in the Windows SDK. For more information, see the TreeView_GetItemPartRect macro.

Requirements

Header: afxcmn.h

This method is supported in Windows Vista and later.

Additional requirements for this method are described in Build Requirements for Windows Vista Common Controls.

Example

The following code example defines a variable, m_treeCtrl, that is used to access the current tree-view control. The code example also defines an unsigned integer and several HTREEITEM variables. These variables are used in the next example.

public:
    // Variable to access tree control.
    CTreeCtrl m_treeCtrl;
    // Variable to access splitbutton control.
    CSplitButton m_splitbutton;
    // Accessibility identifier
    UINT accIdUS;
    // HTREEITEMs
    HTREEITEM hCountry;
    HTREEITEM hPA;
    HTREEITEM hWA;

The following code example uses an accessibility identifier and the CTreeCtrl::MapAccIdToItem method to retrieve a handle to the root tree-view item. Then the example uses the handle and the CTreeCtrl::GetItemPartRect method to draw a 3D rectangle around that item. In an earlier section of the code example, which is not shown, we created a tree-view that consists of a root country node for the United States, subnodes for the states of Pennsylvania and Washington, and tree items for cities in those states. We used the CTreeCtrl::MapItemToAccID method to associate the root tree-view item with an accessibility identifier.

    CRect rect;
    HTREEITEM hUS = m_treeCtrl.MapAccIdToItem( accIdUS );
    m_treeCtrl.GetItemPartRect( hUS, TVGIPR_BUTTON, &rect );
    m_treeCtrl.GetDC()->Draw3dRect( &rect, RGB(255, 0, 0), RGB(0, 0, 255));

See Also

Reference

CTreeCtrl Class

Hierarchy Chart

TreeView_GetItemPartRect

RECT

CTreeCtrl::HitTest

Other Resources

CTreeCtrl Members