问题如上,我是为了得到该项的图标在CImageList的序号,结果发现只有在LVITEM结构体里有一项
int iImage;可是我在 msdn里没看到什么函数可以返回一个LVITEM结构体,请问怎样才能得到啊?
谢谢!

解决方案 »

  1.   

    CListCtrl::GetItem
    BOOL GetItem( LVITEM* pItem ) const;Return ValueNonzero if successful; otherwise zero.ParameterspItemPointer to anLVITEM structure that receives the item’s attributes.ResRetrieves some or all of a list view item’s attributes.
      

  2.   

    谢谢大家的回答,我发觉问题所在,我双击list某项时,它并没有将焦点置在该项上,所以我使用出错
    LVITEM pItem ;
    BOOL FALG = list.GetItem ( &pItem );
    int image = pItem.iImage;
    那么现在怎样根据当前行和列来置它的焦点呐?附得到行和列位置的代码
    LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR;
    int nItem = temp->iItem;
    int nSubItem = temp->iSubItem;
    if( nSubItem == -1 || nItem == -1)
    return ;请大家回答,谢了!
      

  3.   

    获取ListCtrl中选中的行列号
    void CMyListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult) 
    {
    CPoint pt;
    GetCursorPos(&pt);
    ScreenToClient(&pt); LVHITTESTINFO info;
    info.pt = pt;
    info.flags = LVM_SUBITEMHITTEST ;
    int i= SubItemHitTest(&info);

    *pResult = 0;
    }columnint CMyListCtrl::HitTestEx(CPoint &point, int *col) const
    {
    int colnum = 0;
    int row = HitTest( point, NULL );

    if( col ) *col = 0; // Make sure that the ListView is in LVS_REPORT
    if( (GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT )
    return row; // Get the top and bottom row visible
    row = GetTopIndex();
    int bottom = row + GetCountPerPage();
    if( bottom > GetItemCount() )
    bottom = GetItemCount();

    // Get the number of columns
    CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
    int nColumnCount = pHeader->GetItemCount(); // Loop through the visible rows
    for( ;row <= bottom;row++)
    {
    // Get bounding rect of item and check whether point falls in it.
    CRect rect;
    GetItemRect( row, &rect, LVIR_BOUNDS );
    if( rect.PtInRect(point) )
    {
    // Now find the column
    for( colnum = 0; colnum < nColumnCount; colnum++ )
    {
    int colwidth = GetColumnWidth(colnum);
    if( point.x >= rect.left 
    && point.x <= (rect.left + colwidth ) )
    {
    if( col ) *col = colnum;
    return row;
    }
    rect.left += colwidth;
    }
    }
    }
    return -1;
    }
      

  4.   

    SetSelectionMark函数,参数是行,详见MSDN
      

  5.   

    ListView_GetItemState(hWnd, Row, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);hWnd: ListCtrl窗口句柄;
    Row:  某行;
    LVIS_SELECTED  设定选中;
    LVIS_FOCUSED   设定高亮;还可以用SetItem(...);LVITEM lvlv.mask = LVIF_STATE;lv.satemask = LVIS_SELECTED | LVIS_FOCUSED;SetItem(&lv);