class CMixerListBox : public CListBox
.
.
.
void CMixerListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
.
.
.
CMixerListBox mixer;
.
.
.
int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{ if (CView::OnCreate(lpCreateStruct) == -1)
return -1; CRect rectDummy (0, 0, 200, 200);
mixer.Create(WS_VISIBLE|WS_BORDER,rectDummy, this, 1); return 0;
}
但为么如此建立的ListBox,却不能执行其中改写的DrawItem函数?而我把放到模式对话框中却能执行?

解决方案 »

  1.   

    LBS_OWNERDRAWFIXED   The owner of the list box is responsible for drawing its contents; the items in the list box are the same height.
    LBS_OWNERDRAWVARIABLE   The owner of the list box is responsible for drawing its contents; the items in the list box are variable in height.
      

  2.   

    up,在PreCreateWindow 的时候将风格改成 OwnerDraw
      

  3.   

    派生控件子类时,如果要确保控件具有某style,应该将改变style的代码写在PreSubclassWindow虚函数中virtual void PreSubclassWindow();void CMixerListBox::PreSubclassWindow()
    {
    ModifyStyle(0, LBS_OWNERDRAWFIXED);
    CListBox::PreSubclassWindow();
    }