다음을 통해 공유


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