Determining right click on the header control

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >


One of the notification that the header control sends is the HDN_ITEMCLICK notification. This leads us to wrongly expect a corresponding notification for a right click. The control does send a notification for a right button click, but this is a generic notification sent by all new controls in the form of NM_RCLICK. Although you can use a message map entry to add a handler for this notification message, don't use the class wizard. The class wizard adds an entry corresponding to the notification sent by the listview control to its parent and not the notification sent by the header control to the listview control.

You can add a check for the NM_RCLICK notfication in the OnNotify() function as shown below.

BOOL CMyListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 
{
	HD_NOTIFY	*pHDN = (HD_NOTIFY*)lParam;

	LPNMHDR pNH = (LPNMHDR) lParam; 
	// wParam is zero for Header ctrl
	if( wParam == 0 && pNH->code == NM_RCLICK )
	{
		// Right button was clicked on header
		CPoint pt(GetMessagePos());
		CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
		pHeader->ScreenToClient(&pt);
		
		// Determine the column index
		int index;
		CRect rcCol;
		for( int i=0; Header_GetItemRect(pHeader->m_hWnd, i, &rcCol); i++ )
		{
			if( rcCol.PtInRect( pt ) )
			{
				index = i;
				break;
			}
		}

		// Add your right click action code 
	}
}

 



Comments

  • Awesome

    Posted by Legacy on 12/27/2003 12:00am

    Originally posted by: Lawrence Fong

    It is awesome! It is exactly what I am looking for.

    Reply
  • Thanks 2

    Posted by Legacy on 07/24/2000 12:00am

    Originally posted by: Pablo Tom�

    I had been looking for somes functions that you've used here!!!!

    Thanks a lot!!!!!!!

    Reply
  • Sending a notification to the parent

    Posted by Legacy on 10/19/1999 12:00am

    Originally posted by: Mike Burroughs

    I have added the following code where you handle the right click.  
    
    

    NMLISTVIEW NMListView;
    NMListView.hdr.code = LVEXN_COLUMNRCLICK;
    NMListView.hdr.hwndFrom = this->m_hWnd;
    NMListView.hdr.idFrom = GetDlgCtrlID( );
    NMListView.iSubItem = i;

    CWnd* pWnd = GetParent( );
    pWnd->SendMessage( WM_NOTIFY,
    GetDlgCtrlID( ),
    (LPARAM)&NMListView );
    return TRUE;


    This snippet of code causes a notification message to be sent to the parent so you can capture it in the same fashion that you capture the LVN_COLUMNCLICK.

    In the header for CListViewEx I added the following define.

    #define LVEXN_COLUMNRCLICK (LVN_LAST-1)


    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Chuze Fitness is a fast-growing fitness chain with over 21 locations spanning California, Arizona and Colorado. Chief information and marketing officer, Kris Peterson, explains why access to fast and reliable Wi-Fi is a "must have" service at their gyms and why they switched to Ruckus Cloud Wi-Fi. Chuze Fitness needed to provide a good user experience to the hundreds of guests streaming music, podcasts and videos as they worked out. They also needed to adequately cover their sprawling 20-40,000 square foot …

  • In this era of Big Data, enterprise applications create a large volume of data that may be structured, semi-structured, or unstructured in nature. Application development cycles are also shorter and application availability is a critical requirement. As such, enterprises are forced to look beyond traditional relational databases to NoSQL databases, such as MongoDB and Apache Cassandra, to onboard these next-generation applications. This guide discusses the backup and recovery challenges for distributed and …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date