CListCtrl::GetItemRect
擷取一個項目的部分或全部的週框 (Bounding Rectangle) 目前檢視的。
BOOL GetItemRect(
int nItem,
LPRECT lpRect,
UINT nCode
) const;
參數
nItem
位置要擷取之項目的索引。lpRect
接收週框 的長度 結構的位址。nCode
清單檢視項目的部分可以擷取週框。 它可以是下列其中一個值:LVIR_BOUNDS 傳回整個項目的週框,包括圖示和標籤 (Label)。
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