子类化CComboBox的listbox
代码如下
HBRUSH CLocalComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if(nCtlColor == CTLCOLOR_LISTBOX && m_list.GetSafeHwnd() == NULL)
{
m_list.SubclassWindow(pWnd->GetSafeHwnd());
} HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
}这时m_list已经具有自绘属性 (因为m_list的DrawItem虚函数已经可以被调用,估计是因为我CLocalComboBox设置了自绘属性)但是m_list的MeasureItem函数却一次也调用不到。这个问题该如何解决?

解决方案 »

  1.   

    你设置的是哪个ownerdraw呢?fixed还是variable
      

  2.   

    If the list box is created with the LBS_OWNERDRAWVARIABLE style, the framework calls this member function for each item in the list box. Otherwise, this member is called only once.
      

  3.   

    有两种不同的自绘风格,一种是控件创建时触发MeasureItem事件,一种是添加Item时触发
      

  4.   

    listbox的自绘属性是由Combobox决定的。