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

  • Many enterprises are working with an IT architecture that's evolved over time. As business needs evolve, IT must decide whether to modernize incrementally, or all at once. Each approach has its benefits and drawbacks. Identity Management is key to modernizing IT; it plays a crucial role in migrating to cloud apps like Office 365 or HR information systems, building web and mobile apps, and opening developer access to business systems. Read how Okta's modern approach to identity management helps business lower …

  • This case study will highlight the opportunity for mobile and cloud technologies in the Public Sector—specifically for state, local and federal government agencies -where secure mobile application access can offer key productivity gains

Most Popular Programming Stories

More for Developers

RSS Feeds

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