CMyListCtrl
находится в режиме виртуальных данных и владелец рисует. A LVN_GETDISPINFO
уведомление отправляется, когда элемент управления хочет данные.CListCtrl отображает вставленный элемент несколько раз
Код ниже работает отлично, за исключением того, что он отображает каждую строку несколько раз.
В документации говорится, что если я установил флаг маски LVIF_DI_SETITEM
, это не будет сделано. В документах также указывается, что pItem->iGroupId
должен быть установлен до InsertItem
, который я тоже сделал, но элемент управления по-прежнему отображает много строк для каждой вставленной строки.
void CMyListCtrl::OnLvnGetdispinfo(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
//Create a pointer to the item
LV_ITEM* pItem= &(pDispInfo)->item;
CString text, strippedText;
//Does the control need text information?
if(pItem->mask & LVIF_TEXT)
{
if(pItem->iSubItem == 0) // only first column used
{
text.Format(L"%s", cacheNotifyVect[ cacheNdx ]);
//Copy the text to the LV_ITEM structure
lstrcpyn(pItem->pszText, text, pItem->cchTextMax);
pItem->mask |= LVIF_DI_SETITEM; // documentation says to set this so the list-view control will store the requested data and will not ask for it again. The application must set the iGroupid member of the LVITEM structure.
}
}
*pResult = 0;
}
void CMyListCtrl::AddNotifyString(const CString & outListStr)
{
cacheNotifyVect[ cacheNdx % CACHE_CAPACITY] = outListStr; // RT:130908: make cache round robin for notify
LVITEM item;
item.mask = LVIF_TEXT;
item.iItem = cacheNdx++;
item.iSubItem = 0;
item.iGroupId = I_GROUPIDNONE; // so control will store data internally
item.pszText = (LPTSTR)(LPCTSTR)(outListStr);
outputWnd->outputNotify.InsertItem(&item);
Спасибо за ответ и понимание. – rtischer8277
Оказалось, что я неправильно выполнил кнопку прокрутки. Поэтому, когда я прокручивал вверх или вниз, линии бы «повторялись» на экране. – rtischer8277