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

  • Whether a mandate to secure all web and mobile apps comes from a newly enlightened CIO or in response to a major security breach, beginning even a small application security program can be a daunting task. How will you know how many digital assets you have, let alone their risk profile? In this webinar we explore how, using a cloud solution like Fortify on Demand, even the largest organizations can begin to scan apps immediately and rapidly scale an application security program. Identify and risk rank assets, …

  • MongoDB has the flexibility, adaptability and extensibility to embrace widely varying data types and rapid design/deployment cycles. Combining MongoDB with our 5100 ECO Enterprise SSD brings amazing results in smaller, simpler deployments compared to legacy storage. In this technical brief, we compare two MongoDB test clusters, each using the Linux Logical Volume Manager (LVM) for RAID configuration: 5100 ECO 3-node cluster: Two Micron 5100 ECO (1.92TB) per node configured as a software RAID 0 (LVM) Legacy …

Most Popular Programming Stories

More for Developers

RSS Feeds

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