winapilistboxwtlownerdrawnondrawitem

Why the DrawItem method of my owner draw listbox can't be called


I try to write a owner draw listbox with WTL. My code looks like this

template<class T, class TBase = CListBox, class TWinTraits = CControlWinTraits>
class ATL_NO_VTABLE CMyListBoxImpl : 
   public CWindowImpl< T, TBase, TWinTraits >,
   public COwnerDraw< T >
{
...
BEGIN_MSG_MAP(CMyListBoxImpl)
    MESSAGE_HANDLER(WM_CREATE, OnCreate)
    MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
    MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)
    MESSAGE_HANDLER(WM_SIZE, OnSize) 
    MESSAGE_HANDLER(WM_DRAWITEM, OnDrawItem)
    CHAIN_MSG_MAP(COwnerDraw< T >)
    DEFAULT_REFLECTION_HANDLER()
END_MSG_MAP()

...

void Init()
{
    ...
    ModifyStyle(0, BS_OWNERDRAW | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
    ...
}
void DrawItem(LPDRAWITEMSTRUCT lpdis)
{
  ...

I also added REFLECT_NOTIFICATIONS in the parent's message loop, and set Owner Draw to Fixed in property sheet. But I still can't receive the message. Then I used spy++ to examine the message that the listbox receive, I found some message that is very strange (WM_USER+7211).
My os is WinXp and use VS2008.


Solution

  • This forum thread might also be of help...