CListCtrl::GetItemRect
检索一个项的全部或部分的边框在当前视图的。
BOOL GetItemRect(
int nItem,
LPRECT lpRect,
UINT nCode
) const;
参数
nItem
位置要检索项的索引。lpRect
接收边框 RECT 结构的地址。nCode
列表视图项的节中检索边框。 它可以是以下值之一:LVIR_BOUNDS 返回整个项目的边框,包括该图标和标签。
LVIR_ICON 返回图标或小图标的边框。
LVIR_LABEL 返回项文本的边框。
返回值
非零,如果成功;否则零。
示例
// OnClick is the handler for the NM_CLICK notification
void CListCtrlDlg::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
UNREFERENCED_PARAMETER(pResult);
LPNMITEMACTIVATE pia = (LPNMITEMACTIVATE)pNMHDR;
// Get the current mouse location and convert it to client
// coordinates.
CPoint pos( ::GetMessagePos() );
ScreenToClient(&pos);
// Get indexes of the first and last visible items in
// the listview control.
int index = m_myListCtrl.GetTopIndex();
int last_visible_index = index + m_myListCtrl.GetCountPerPage();
if (last_visible_index > m_myListCtrl.GetItemCount())
last_visible_index = m_myListCtrl.GetItemCount();
// Loop until number visible items has been reached.
while (index <= last_visible_index)
{
// Get the bounding rectangle of an item. If the mouse
// location is within the bounding rectangle of the item,
// you know you have found the item that was being clicked.
CRect r;
m_myListCtrl.GetItemRect(index, &r, LVIR_BOUNDS);
if (r.PtInRect(pia->ptAction))
{
UINT flag = LVIS_SELECTED | LVIS_FOCUSED;
m_myListCtrl.SetItemState(index, flag, flag);
break;
}
// Get the next item in listview control.
index++;
}
}
要求
Header: afxcmn.h