views:

101

answers:

1

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


template
class ATL_NO_VTABLE CMyListBoxImpl : 
   public CWindowImpl,
   public COwnerDraw
{
...
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)
    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 very strange (WM_USER+7211). Hope someone can help me and point out the mistake I made.

My os is WinXp and use VS2008. Thanks.

+1  A: 
  • BS_OWNERDRAW? That is a button style.
  • Even with LBS_OWNERDRAWFIXED, you still need to handle WM_MEASUREITEM.
  • Some control styles (like) LBS_OWNERDRAWFIXED can only be set when the control is created (Is that what you mean by "and set Owner Draw to Fixed in property sheet"?, if so, why modify the style in code?)

This forum thread might also be of help...

Anders