Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Handling right-click on the CListCtrl header control

0.00/5 (No votes)
7 May 2000 1  
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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here