Handling Title Tips With Drag/Drop Headers Using The Visual C++ 6.0 CListCtrl
Posted
by Kevin Delgado
on September 2nd, 1998
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!