CListCtrl中怎么获得当前可以显示的最后一个item的index?

gussing 2006-04-30 02:28:41
比如说我滚动scroll bar后最后一行可见的是第50行
用程序怎么动态的得到这个index?
...全文
248 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Snow_Ice11111 2006-05-07
  • 打赏
  • 举报
回复
List或Report模式下可以用你的CListCtrl::GetTopIndex()得到可见第一个,再加上CListCtrl::GetCountPerPage()得到每页Item的数量,再简单的加一下就知道了。
lesheng 2006-05-05
  • 打赏
  • 举报
回复
下面的代码是MFC programmer's SOURCEBOOK中的一部分供参考:
// HitTestEx - Determine the row index and column index for a point
// Returns - the row index or -1 if point is not over a row
// point - point to be tested.
// col - to hold the column index
int CSLList::HitTestEx(CPoint &point, int *col) const
{
int colnum = 0;
int row = HitTest( point, NULL );

if( col ) *col = 0;

// Make sure that the ListView is in LVS_REPORT
if( (GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT )
return row;

// Get the top and bottom row visible
row = GetTopIndex();
int bottom = row + GetCountPerPage();
if( bottom > GetItemCount() )
bottom = GetItemCount();

// Get the number of columns
CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
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 );
if( rect.PtInRect(point) )
{
// Now find the column
for( colnum = 0; colnum < nColumnCount; colnum++ )
{
int colwidth = GetColumnWidth(colnum);
if( point.x >= rect.left
&& point.x <= (rect.left + colwidth ) )
{
if( col ) *col = colnum;
return row;
}
rect.left += colwidth;
}
}
}
return -1;
}
gussing 2006-04-30
  • 打赏
  • 举报
回复
已经解决

m_List.GetTopIndex()得到可见的第一行
laogong165 2006-04-30
  • 打赏
  • 举报
回复
// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;

// Ensure that the last item is visible.
int nCount = pmyListCtrl->GetItemCount();
if (nCount > 0)
pmyListCtrl->EnsureVisible(nCount-1, FALSE);

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧