- 更新闪烁可以使用双缓冲 LVS_EX_DOUBLEBUFFER
也可以使用 SetRedraw
- 滚动到指定位置, 如恢复到更新前的位置用 CListCtrl.Scroll
具体位置需要计算, 方法有两个
a. 用GetScrollPos, GetScrollInfo, 相乘得到大小
b. 用 GetTopIndex, GetItemRect 相乘得到大小
- 更新时会导致滚动条跳动一下, 其他不影响,
跳动问题可以用 LockWindowUpdate, UnlockWindowUpdate 代替 SetRedraw 避免这个问题
BOOL CFilePatherDlg::ShowPathList(BOOL bKeepSel)
{
list<PATH_ITEM>::iterator Iter;
std::vector<int> SelList;
PATH_ITEM *pItem;
TCHAR szBuffer[4096];
SCROLLINFO SclInfo;
int nIndex, i, nCount, nSclH, nSclV, nSclHeight;
CRect rct;
NWnd::SetDlgItemTexts(GetSafeHwnd(), IDC_EDIT1, m_szDestPath);
if(bKeepSel)
NDlg::ListCtrl_GetSelectItems(m_List.GetSafeHwnd(), SelList);
nSclH = m_List.GetScrollPos(SB_HORZ);
nSclV = m_List.GetScrollPos(SB_VERT);
m_List.GetScrollInfo(SB_VERT, &SclInfo);
nSclHeight = SclInfo.nPage * nSclV;
m_List.LockWindowUpdate();
m_List.DeleteAllItems();
nIndex = 0;
for(Iter = m_PathList.begin();
Iter != m_PathList.end();
Iter ++)
{
pItem = &*Iter;
_sntprintf(szBuffer, countof(szBuffer), _T("%08x"), pItem->dwOffset[0]);
m_List.InsertItem(nIndex, szBuffer);
NStr::Char2TChar((CHAR*)pItem->sDescrip.c_str(), szBuffer, sizeof(szBuffer)); m_List.SetItemText(nIndex, 1, szBuffer);
NStr::Char2TChar((CHAR*)pItem->sOldHex.c_str(), szBuffer, sizeof(szBuffer)); m_List.SetItemText(nIndex, 2, szBuffer);
NStr::Char2TChar((CHAR*)pItem->sNewHex.c_str(), szBuffer, sizeof(szBuffer)); m_List.SetItemText(nIndex, 3, szBuffer);
_tcscpy(szBuffer, pItem->bPath ? _T("Yes") : _T("No")); m_List.SetItemText(nIndex, 4, szBuffer);
m_List.SetItemData(nIndex, (LPARAM)pItem);
nIndex ++;
}
SortList();
nCount = (int)SelList.size();
for(i=0; i<nCount; i++)
{
NDlg::ListCtrl_SelectItem(m_List.GetSafeHwnd(), SelList[i], TRUE);
}
if(nSclHeight)
m_List.Scroll(CSize(0, nSclHeight));
m_List.UnlockWindowUpdate();
ChangeStat(SS_Ready);
return TRUE;
}