我自己派生了一个类
void CColorComboEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rc = lpDrawItemStruct->rcItem;
int nNumItem = lpDrawItemStruct->itemID;
CBrush bf;
if (nNumItem == -1)//可是很郁闷的是debug的时候这个地方总是-1,怪不得我看不到画出来的东西
return;
rc.bottom -= 2;
CString szFontName;
//class CColorComboEx:public CComboBox其中在资源中的COmboBox的属性为
Drop List
Owner draw Variable
Has String
V Vscroll实在不解,请大家帮帮忙·!
谢谢!

解决方案 »

  1.   

    http://www.codersource.net/mfc_ccombobox_ownerdraw_color.html
      

  2.   

    参考:http://www.vccode.com/file_show.php?id=15
      

  3.   

    你下拉了吗?
    下拉之后还是这样的话,那就有问题了!或者执行SetCurSel,选中一个,然后看看结果怎么样?
      

  4.   

    if (nNumItem == -1)//?单看这几行代码看不问题,如果可以,把代码发给我看看?
      

  5.   

    你的ComboBox是怎么创建的,自类化了吗?
      

  6.   

    在MSDN上面有这么一句话!
     For an empty list box or combo box, this member is a negative value
    可是我保证我又向里面添加条目呀!
    真是见鬼了呢!
    哦!
    我的程序是这样的!
    // Dialog Data
    //{{AFX_DATA(CEditCharConfigDlg)
    enum { IDD = IDD_DIALOG_EDIT_CHAR_CONFIG };
    CComboSize m_ComboSize;
    CComboFont m_ComboFont;
    CColorComboEx m_ComboColor;
    //}}AFX_DATA其中
    class   CComboSize;
    class   CColorcComboEx;
    class   CComboFont;
    都是派生自ComboBox
    然后在一个对话框上面增加了3个ComboBox。把属性设置为
    Drop List
    Owner draw Variable
    Has String
    V Vscroll
    再添加成员定义,并且改成如上所示。
    难道这个样子,它就不调用我的派生类的Create函数了吗!
    因为我的添加条目的DD都在OnCreate函数里面
    OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {

    ?????
      

  7.   

    先调试一下,看框架有没有调用你的DrawItem函数
    如果没有那么在初始化对话框函数中加入如下代码!
    ((CColorComboEx*)GetDlgItem(IDC_XXXX))->ModifyStyle(0,CBS_OWNERDRAWFIXED);
      

  8.   

    我终于找到了一点头绪,不过还是需要大家多多帮忙!
    我的数据初始化时在
    ComboBox的OnCreate函数进行的
    int CColorComboEx::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    。。
    // TODO: Add your specialized creation code here
    extern char gComboDummyChar;
    //gComboDummyChar="";
    for (int nColors = 0; nColors < colors.GetSize(); nColors++)
    // Add a dummy string for every array item so that WM_DRAWITEM message is sent.
    {
    SendMessage(CB_ADDSTRING,0,(LPARAM)&gComboDummyChar);
    }

    // Select the first color when the control is created.
    //在这里增加了一个变量
             int Total=GetCount();
    //调试的时候数据正确,total=15
    SetCurSel(3);
    return 0;
    }
    然后再在DrawItem函数里面在设置检验变量
    void CColorComboEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
    int Toltal=GetCount();//这个时候得到的Total=0;
    //这个就是我想不通的地方,我明明添加了数据,并且在Oncreate函数中都是正确的
    //为什么到了这个地方就不对了,一个数据都没有了!
    if(lpDrawItemStruct->CtlType!=ODT_COMBOBOX)
    return;麻烦大家了!
    预祝大家是圣诞快乐!