Share via


CListCtrl::GetItemRect

Recupera el rectángulo delimitador del todo o parte de un elemento en la vista actual.

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

Parámetros

  • nItem
    El índice del elemento cuya posición es recuperar.

  • lpRect
    dirección de una estructura de RECT que recibe el rectángulo delimitador.

  • nCode
    Parte del elemento de vista de lista para recuperar el rectángulo delimitador.puede ser uno de estos valores:

    • LVIR_BOUNDS devuelve el rectángulo delimitador del elemento completo, incluido el icono y la etiqueta.

    • LVIR_ICON devuelve el rectángulo delimitador del icono o el icono pequeño.

    • LVIR_LABEL devuelve el rectángulo delimitador del texto del elemento.

Valor devuelto

Distinto de cero si correctamente; si no cero.

Ejemplo

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

Requisitos

encabezado: afxcmn.h

Vea también

Referencia

Clase de CListCtrl

Gráfico de jerarquía

CListCtrl::GetItemPosition

CListCtrl::SetItemPosition

CListCtrl::GetOrigin