MFC Owner Draw Listbox - GetItemDataPtr returning garbage

426 Views Asked by At

So I've derived my listbox from CListbox, set the resource style up to be just like the demo project I got (HASSTRINGS, OWNERDRAW - VARIABLE, NO SORT).

The listbox populates, draws OK, TRACE statements give me the pointer value for each item being drawn.

Until I scroll.

Before I scroll the item at the bottom of the visible list is traced as (20 is the lpDrawItemStruct->itemID)

MyClass::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) ...

20 - 0x036f3d90 {m_Event={ size=658 } m_ListName= ...

The first DrawItem event I handle after the scroll

20 - 0x0127d248 {m_Event={ size=1073736252 } m_ListName= m_ImageName=...} - The evaluation was aborted because an unhandled exception occurred.

Why is the pointer different?

It doesn't need the scroll to reproduce this problem, selection does it too.

Any bright sparks out there can tell me what to look for?

0

There are 0 best solutions below