我自己在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.大致意思明白,但是此问题如何解决呢?还往诸位拨开迷雾,谢谢!

解决方案 »

  1.   

    发现覆盖MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) 填一个高度就可以了。
    现在求完全自绘的Combo代码,下拉list、按钮等等全是自己画的,那位有麻烦给我一份。
    我这里还有一个问题,如我贴出代码的自绘Combo,在create时加上CBS_OWNERDRAWFIXED后,一旦AddString,再GetLBText出来,字符串就是很奇怪的一个东西;而不加S_OWNERDRAWFIXED则一切正常,我还要覆盖什么东西或是设置什么属性么?
      

  2.   

    嗨,还不是为了画着好看,有些人嫌windows的土呗!
      

  3.   

    我想自绘combo下拉框的边框,有人说能拿到combo自己list的handle,是真的么?我该怎么做?怎么我的问题人气这么少?真的这么无聊么?
      

  4.   

    现在我把问题细化,问问怎样能将combo的下拉框的黑色边框去掉或覆盖,我在combo的OnPaint或是DrawItem里修改都不行,谁有良策?