或者取得可视范围中最左上角的item编号也可以

解决方案 »

  1.   

    CListCtrl List;
    CRect rect;
    List.GetWindowRect(&rect);根据rect得到最左上角的item的一个点的坐标再模拟一下鼠标左键在该点的点击后在OnClickFreqList中下面调用,nItem即为结果 :int nItem ;
    POSITION pos = pList->GetFirstSelectedItemPosition();
    if (pos == NULL)
       TRACE0("No items were selected!\n");
    else
    {
       while (pos)
       {
          nItem = pList->GetNextSelectedItem(pos);
          TRACE1("Item %d was selected!\n", nItem);
          // you could do your own processing on nItem here
       }
    }
      

  2.   

    Sorry,没仔细看楼主的要求,CListCtrl::GetTopIndex只能在list和report模式下得到可见第一个项目。
      

  3.   

    用CListCtrl::GetItemPosition函数把控件中的Item一个个坐标找过去,最接近客户区0,0的就是可见的第一个Item.
      

  4.   

    CString str;
    CRect rect;
    m_cListCtrl.GetViewRect(&rect);
    CPoint pt,pt1(100,100);
    int first;
    for(int i=0;i<m_cListCtrl.GetItemCount()-1;i++)
    {
    m_cListCtrl.GetItemPosition(i,&pt);
    pt.y+=rect.top;
    if(pt.x<=pt1.x && pt.y<=abs(pt1.y)) 
    {
    pt1=pt;
    first=i;
    }
    }

    str.Format("目标为第%d项,坐标:%d,%d",first,pt.x,pt.y+=rect.top);
    AfxMessageBox(str);
    -----------------------------------------------------------------------------------
    上面的代码就可以在大、小图标模式下得到可见第一个项目。
      

  5.   

    上面代码中m_cListCtrl为ListCtrl控件绑定变量,str.Format那行的代码也要小改一下:str.Format("目标为第%d项,坐标:%d,%d",first,pt1.x,pt1.y);    //改成这样得到控件中第一个可见Item后,配合CListCtrl::GetCountPerPage就可得到控件中所有可见Item。