Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / MFC

Handling right-click on the CListCtrl header control

Rate me:
Please Sign up or sign in to vote.
4.47/5 (13 votes)
7 May 2000CPOL 100.4K   30   4
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader www.unitronics.com
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalother solution... Pin
hopkins8-May-07 10:57
hopkins8-May-07 10:57 
GeneralYour a good man! Pin
hannahb23-May-05 5:47
hannahb23-May-05 5:47 
GeneralSimple problem, please help Pin
haiaw12-Sep-04 23:42
haiaw12-Sep-04 23:42 
Generalthanks! Pin
jrivero2-May-03 6:47
jrivero2-May-03 6:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.