有关自绘Combo与WM_MEASUREITEM的问题
我自己在view中create了一个combo:
g_MyCombo.Create(CBS_DROPDOWNLIST|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP, rc, this, ID_MYCOMBO);
此combo是从CComboBox继承而来,覆盖了OnPaint,在view中画出来,到这一步一切正常。
后来想覆盖CComboBox的DrawItem,使我的combo的下拉框的背景以及字符颜色都由我来控制;但是覆盖了DrawItem后并不起作用。
于是我在create的时候加了一个属性——CBS_OWNERDRAWFIXED,希望能使DrawItem起作用:
g_MyCombo.Create(CBS_DROPDOWNLIST|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|CBS_OWNERDRAWFIXED, rc, this, ID_MYCOMBO);
结果这样一来程序报错,发现在CComboBox::OnChildNotify里面响应WM_MEASUREITEM时调用:
void CComboBox::MeasureItem(LPMEASUREITEMSTRUCT)
{ ASSERT(FALSE); }
查询msdn有关OnMeasureItem的篇幅,看到如下文字:
Windows initiates the call to OnMeasureItem for the owner of combo boxes and list boxes created with the OWNERDRAWFIXED style before sending theWM_INITDIALOG message. As a result, when the owner receives this call, Windows has not yet determined the height and width of the font used in the control; function calls and calculations that require these values should occur in the main function of the application or library.
大致意思明白,但是此问题如何解决呢?还往诸位拨开迷雾,谢谢!