Handling right-click on the CListCtrl header control






4.56/5 (12 votes)
Determining the right click on the header of the CListCtrl
A good way to handle a right click on the header control of a list control is to use the HDM_HITTEST
message to determine on which header item the user right clicked.
Here is an example:
BOOL CMyListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { if( wParam==0 && ((NMHDR*)lParam)->code == NM_RCLICK) { POINT Point; GetCursorPos (&Point); ScreenToClient(&Point); HDHITTESTINFO HitTest; //Offset of right scrolling HitTest.pt.x = Point.x+ GetScrollPos(SB_HORZ); //Offset of right scrolling HitTest.pt.y = Point.y; //Send the Hit Test Message GetHeaderCtrl()->SendMessage(HDM_HITTEST,0,(LPARAM)&HitTest); ..... } ..... }
The HDHITTESTINFO
structure holds the column index in its iItem member.