HitTest for CListCtrl
-
as I understand HitTest should return the index of CListCtrl's item that been clicked, or -1. CPoint point; GetCursorPos(&point); UINT uFlags; int nIndex=m_lstLeft.HitTest(point,&uFlags); nIndex==-1... always
GetCursorPos returns the mouse position in screen coordinates. Try this:
CPoint point; GetCursorPos(&point); **m_lstLeft.ScreenToClient(&point);** UINT uFlags; int nIndex=m_lstLeft.HitTest(point,&uFlags);
- S 50 cups of coffee and you know it's on!
-
as I understand HitTest should return the index of CListCtrl's item that been clicked, or -1. CPoint point; GetCursorPos(&point); UINT uFlags; int nIndex=m_lstLeft.HitTest(point,&uFlags); nIndex==-1... always
GetCursorPos
offers the position in screen coordinates, whileHitTest
requires client coordinates. You probably have to useScreenToClient
function. Try this:CPoint point; GetCursorPos(point); ScreenToClient(point); UINT uFlags; int nIndex=m_lstLeft.HitTest(point,&uFlags);
-
GetCursorPos
offers the position in screen coordinates, whileHitTest
requires client coordinates. You probably have to useScreenToClient
function. Try this:CPoint point; GetCursorPos(point); ScreenToClient(point); UINT uFlags; int nIndex=m_lstLeft.HitTest(point,&uFlags);
-
anyway smth wrong.. function returns not index of selected Item.. but index of the item+2(or +3) I cant understand why..
The suggested
ScreenToClient
call is for the case you handle the messages within yourCListCtrl
-derived control. Otherwise, if you are in parent dialog, you should try the solution posted by Steve Echols:m_lstLeft.ScreenToClient(&point)
. Please specify in which class you are processing the message. If your problem is to find the selected (highlighted) item, whyGetNextItem(-1, LVNI_ALL | LVNI_SELECTED)
is not suitable for you?