Handling Title Tips With Drag/Drop Headers Using The Visual C++ 6.0 CListCtrl

I wanted to add the title-tip class to the new version of the CListCtrl in Visual C++ 6.0. However, as has previously been pointed out on this site, the code doesn't quite work for a List Control with the LVS_EX_HEADERDRAGDROP style enabled. The code fix previously posted is more complicated than neccessary with the new CListCtrl class in VC 6, and I was able to modify Zafir Anjum's CellRectFromPoint() function to handle all header cases simply. Just modify the CellRectFromPoint() code to look like the following:


int CTRListCtrl::CellRectFromPoint(CPoint & point, RECT * cellrect, int * col) 
{	
	int colnum;	
	
	// Make sure that the ListView is in LVS_REPORT
	if( (GetStyle() & LVS_TYPEMASK) != LVS_REPORT )		
		return -1;
	
	// Get the top and bottom row visible	
	int row = GetTopIndex();
	int bottom = row + GetCountPerPage();	
	if( bottom > GetItemCount() )
		bottom = GetItemCount();		
		
	// Get the number of columns
	CHeaderCtrl* pHeader = CListCtrl::GetHeaderCtrl();
	int nColumnCount = pHeader->GetItemCount();	
	
	// Loop through the visible rows
	for( ;row <= bottom; row++)	
	{
		// Get bounding rect of item and check whether point falls in it.		
		CRect rect;
		GetItemRect( row, &rect, LVIR_BOUNDS );		

		// We use the rects of the header items to determine if the point falls in a
		// given column. Thus, the order of the columns is no longer important.

		CRect colRect;
		
		if( rect.PtInRect(point) )		
		{
			// Now find the column			
			for( colnum = 0; colnum < nColumnCount; colnum++ )
			{				
				pHeader->GetItemRect(colnum, &colRect);
									
				if(  (point.x >= colRect.left) && (point.x <= (colRect.left + colRect.Width()) ) )
				{					
					// Found the column
					RECT rectClient;					
					GetClientRect( &rectClient );
					if( point.x > rectClient.right )						
						return -1;					
						
					if( col ) 
						*col = colnum;					
						
					rect.right = colRect.left + colRect.Width();
					rect.left = colRect.left;

					if( rect.right > rectClient.right ) 						
						rect.right = rectClient.right;
					
					*cellrect = rect;					
					return row;				
				}				
			}		
		}	
	}
	return -1;
}




Comments

  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds