Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize


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

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


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


Point to be tested.


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 Windows SDK.

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

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.

void CListCtrlDlg::OnRClick(NMHDR* pNMHDR, LRESULT* pResult)
	CPoint point(pia->ptAction);

	// Select the item the user clicked on.
	UINT uFlags;
	int nItem = m_myListCtrl.HitTest(point, &uFlags);

		m_myListCtrl.SetItem(nItem, 0, LVIF_STATE, NULL, 0, LVIS_SELECTED, 

	*pResult = 0;

Header: afxcmn.h

© 2015 Microsoft