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;
HitTest.pt.x = Point.x+ GetScrollPos(SB_HORZ); HitTest.pt.y = Point.y;
GetHeaderCtrl()->SendMessage(HDM_HITTEST,0,(LPARAM)&HitTest);
.....
}
.....
}
The HDHITTESTINFO
structure holds the column index in its iItem member.