Share via


CListCtrl::GetItemRect

現在のビュー アイテムの全体または一部の外接する四角形を取得します。

BOOL GetItemRect(
   int nItem,
   LPRECT lpRect,
   UINT nCode 
) const;

パラメーター

  • nItem
    位置が取得された項目のインデックス。

  • lpRect
    外接する四角形を受け取る RECT の構造体のアドレス。

  • nCode
    外接する四角形を取得するリスト ビューの項目の部分。これらの値の 1 になる場合があります:

    • 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++;
    }
}

必要条件

ヘッダー: afxcmn.h

参照

関連項目

CListCtrl クラス

階層図

CListCtrl::GetItemPosition

CListCtrl::SetItemPosition

CListCtrl::GetOrigin