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.
*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; }
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.
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 ;请大家回答,谢了!
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;
}
Row: 某行;
LVIS_SELECTED 设定选中;
LVIS_FOCUSED 设定高亮;还可以用SetItem(...);LVITEM lvlv.mask = LVIF_STATE;lv.satemask = LVIS_SELECTED | LVIS_FOCUSED;SetItem(&lv);