문제

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.

도움이 되었습니까?

해결책

  • 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...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top