Determining right click on the header control


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

  • Digital transformation is a growing, urgent imperative for organizations worldwide. Subsequently, network resources to support digital initiatives are coming under intense scrutiny. Increasingly, that focus concentrates on the wide area network (WAN), which provides essential connectivity and valuable network services for branch offices, remote sites, and mobile workers. This white paper from IDC examines how digital transformation and cloud computing have necessitated a significant reassessment of the WAN, …

  • Take advantage of this on-demand webinar to learn how to deploy Windows apps to all workers, across all devices, with Citrix XenApp and XenDesktop. Additionally, our cloud expert will teach you to create a Windows 10-based VDI implementation and login using Citrix Receiver. Other key takeaways include how to: Deploy a multi–server Citrix XenApp/XenDesktop infrastructure Understand the core capabilities of Citrix on Azure, including virtualizing applications and desktops Register today!

Most Popular Programming Stories

More for Developers

RSS Feeds

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