CListCtrl::HitTest

int HitTest( LVHITTESTINFO* pHitTestInfo ) const;

int HitTest( CPoint pt, UINT* pFlags = NULL ) const;

Return Value

The index of the item at the position specified by pHitTestInfo, if any, or -1 otherwise.

Parameters

pHitTestInfo

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

pt

Point to be tested.

pFlags

Pointer to an integer that receives information about the results of the test. See the explanation of the flags member of the LVHITTESTINFO structure in the Platform SDK.

Remarks

Determines which list view item, if any, is at a specified position.

You can use the LVHT_ABOVE, LVHT_BELOW, LVHT_TOLEFT, and LVHT_TORIGHT values of the structure's flag member to determine whether to scroll the contents of a list view control. Two of these flags can be combined, for example, if the position is above and to the left of the client area.

You can test for the LVHT_ONITEM value of the structure's flag member to determine whether a given position is over a list view item. This value is a bitwise-OR operation on the LVHT_ONITEMICON, LVHT_ONITEMLABEL, and LVHT_ONITEMSTATEICON values of the structure's flag member.

Example

// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;
// The pointer where the mouse was clicked.
extern CPoint myPoint;

// Select the item the user clicked on.
UINT uFlags;
int nItem = pmyListCtrl->HitTest(myPoint, &uFlags);

if (uFlags & LVHT_ONITEMLABEL)
{
   pmyListCtrl->SetItem(nItem, 0, LVIF_STATE, NULL, 0, LVIS_SELECTED, 
      LVIS_SELECTED, 0);
}

CListCtrl OverviewClass MembersHierarchy Chart

See Also   CListCtrl::GetItemPosition