今天扩展List控件,调用CListCtrl::GetSubItemRect()获取subItem==0项的rect时出了问题,我用TRACE打印数据发现left和right的数值是不正确的,似乎获取到的是整个list控件的大小,后来查了一下MSDN,里面写着:
重写CListCtrl::GetSubItemRect()算哒。。。。。
-_-这下好了。
- iSubItem
-
The one-based index of the subitem.
重写CListCtrl::GetSubItemRect()算哒。。。。。
BOOL GetSubItemRect(
int nItem,
int nSubItem,
int nArea, CRect& rect )
{
ASSERT(nItem >= 0);
ASSERT(nItem < GetItemCount());
if ((nItem < 0) || nItem >= GetItemCount())
return FALSE;
ASSERT(nSubItem >= 0);
ASSERT(nSubItem < GetHeaderCtrl()->GetItemCount());
if ((nSubItem < 0) || nSubItem >= GetHeaderCtrl()->GetItemCount())
return FALSE;
BOOL bRC = CListCtrl::GetSubItemRect(nItem, nSubItem, nArea, rect);
if (nSubItem == 0)
{
int offset = rect.left;
CRect firstColumnRect;
GetHeaderCtrl()->GetItemRect(0, &firstColumnRect);
rect.left = firstColumnRect.left + offset;
rect.right = firstColumnRect.right + offset;
}
return bRC;
}
{
ASSERT(nItem >= 0);
ASSERT(nItem < GetItemCount());
if ((nItem < 0) || nItem >= GetItemCount())
return FALSE;
ASSERT(nSubItem >= 0);
ASSERT(nSubItem < GetHeaderCtrl()->GetItemCount());
if ((nSubItem < 0) || nSubItem >= GetHeaderCtrl()->GetItemCount())
return FALSE;
BOOL bRC = CListCtrl::GetSubItemRect(nItem, nSubItem, nArea, rect);
if (nSubItem == 0)
{
int offset = rect.left;
CRect firstColumnRect;
GetHeaderCtrl()->GetItemRect(0, &firstColumnRect);
rect.left = firstColumnRect.left + offset;
rect.right = firstColumnRect.right + offset;
}
return bRC;
}
-_-这下好了。