ListCtrl列表控件设置到指定位置(自滚动,该特性支持虚拟列表)

程序中的代码,主要看实现思路与步奏

void CxDbgDlg::gotoAddress(DWORD dwAddress)
{
    CString strAddress;
    strAddress.Format(_T("%08X"), dwAddress);
    DWORD dwItem = 0;
    do{
        if (g_pListCpu->GetItemText(dwItem, 0) == strAddress){

            int nItem = g_pListCpu->GetTopIndex();                                 // 获取顶层索引
            CRect rc;
            g_pListCpu->GetItemRect(nItem, rc, LVIR_BOUNDS);
            CSize sz(0, (dwItem - nItem)*rc.Height());                             // 取得要滚动的size
            g_pListCpu->Scroll(sz);                                                // 自滚动
            g_pListCpu->SetItemState(dwItem, LVIS_SELECTED, LVIS_SELECTED);        // 设置状态为被选中
            break;
        }
        ++dwItem;
    } while (TRUE);

}
原文地址:https://www.cnblogs.com/Lthis/p/4701932.html