Click here to Skip to main content
Licence CPOL
First Posted 7 May 2000
Views 75,403
Bookmarked 29 times

Handling right-click on the CListCtrl header control

By | 7 May 2000 | Article
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)

About the Author

Alberto Bar-Noy

Team Leader
www.unitronics.com
Israel Israel

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalother solution... Pinmemberhopkins10:57 8 May '07  
GeneralYour a good man! Pinmemberhannahb5:47 23 May '05  
GeneralSimple problem, please help Pinmemberhaiaw23:42 12 Sep '04  
Generalthanks! Pinmemberjrivero6:47 2 May '03  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 8 May 2000
Article Copyright 2000 by Alberto Bar-Noy
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid