Freigeben über


CTreeCtrl::HitTest

Call this function to determine the location of the specified point relative to the client area of a tree view control.

HTREEITEM HitTest(
   CPoint pt,
   UINT* pFlags = NULL
) const;
HTREEITEM HitTest(
   TVHITTESTINFO* pHitTestInfo 
) const;

Parameters

  • pt
    Client coordinates of the point to test.

  • pFlags
    Pointer to an integer that receives information about the results of the hit test. It can be one or more of the values listed under the flags member in the Remarks section.

  • pHitTestInfo
    Address of a TVHITTESTINFO structure that contains the position to hit test and that receives information about the results of the hit test.

Return Value

The handle of the tree view item that occupies the specified point or NULL if no item occupies the point.

Remarks

When this function is called, the pt parameter specifies the coordinates of the point to test. The function returns the handle of the item at the specified point or NULL if no item occupies the point. In addition, the pFlags parameter contains a value that indicates the location of the specified point. Possible values are:

Value

Meaning

TVHT_ABOVE

Above the client area.

TVHT_BELOW

Below the client area.

TVHT_NOWHERE

In the client area, but below the last item.

TVHT_ONITEM

On the bitmap or label associated with an item.

TVHT_ONITEMBUTTON

On the button associated with an item.

TVHT_ONITEMICON

On the bitmap associated with an item.

TVHT_ONITEMINDENT

In the indentation associated with an item.

TVHT_ONITEMLABEL

On the label (string) associated with an item.

TVHT_ONITEMRIGHT

In the area to the right of an item.

TVHT_ONITEMSTATEICON

On the state icon for a tree-view item that is in a user-defined state.

TVHT_TOLEFT

To the left of the client area.

TVHT_TORIGHT

To the right of the client area.

Example

// Select the item that is at the point myPoint.
UINT uFlags;
HTREEITEM hItem = m_TreeCtrl.HitTest(myPoint, &uFlags);

if ((hItem != NULL) && (TVHT_ONITEM & uFlags))
{
   m_TreeCtrl.SelectItem(hItem);
}

Requirements

Header: afxcmn.h

See Also

Reference

CTreeCtrl Class

Hierarchy Chart

CTreeCtrl::GetItemRect

Other Resources

CTreeCtrl Members

Change History

Date

History

Reason

June 2010

Added flag values.

Customer feedback.