次の方法で共有


CListCtrl::GetItemRect

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

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

パラメーター

  • nItem
    位置を取得するアイテムのインデックス。

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

  • nCode
    リスト ビュー アイテムのどの部分に外接する四角形を取得するかを指定します。 次のいずれかの値を使用できます。

    • LVIR_BOUNDS   アイコンとラベルを含むアイテム全体に外接する四角形を返します。

    • LVIR_ICON   アイコンまたは小さなアイコンに外接する四角形を返します。

    • LVIR_LABEL   アイテムのテキストに外接する四角形を返します。

戻り値

正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。

使用例

// 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

その他の技術情報

CListCtrl のメンバー