如何设置combobox(drop list style)文字的颜色,请注意不是下拉列表项的颜色!

解决方案 »

  1.   

    http://topic.csdn.net/u/20110308/21/c8c3f8d1-c1ae-4e80-871c-70d9dcd68e8c.html?99619
      

  2.   

    void CMyComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)

    ASSERT(lpDrawItemStruct->CtlType == ODT_COMBOBOX); 
    LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData; 
    ASSERT(lpszText != NULL); CDC dc; dc.Attach(lpDrawItemStruct->hDC); 
    // Save these value to restore them when done drawing. 
    COLORREF crOldTextColor = dc.GetTextColor(); 
    COLORREF crOldBkColor = dc.GetBkColor(); 
    // If this item is selected, set the background color // and the text color to appropriate values. Erase 
    // the rect by filling it with the background color. 
    if ((lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED)) 

    dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)); 
    dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); 
    dc.FillSolidRect(&lpDrawItemStruct->rcItem, 
    ::GetSysColor(COLOR_HIGHLIGHT)); 
    }
    else
    dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor); 
    // Draw the text. 
    dc.DrawText( lpszText, strlen(lpszText), &lpDrawItemStruct->rcItem, DT_CENTER|DT_SINGLELINE|DT_VCENTER); 
    // Reset the background color and the text color back to their 
    // original values. 
    dc.SetTextColor(crOldTextColor); 
    dc.SetBkColor(crOldBkColor); 
    dc.Detach();
    }
      

  3.   

    大哥,我把控件的Owen Draw属性改变了后运行你的程序直接崩溃,没改的时候运行你的程序控件没任何反应
      

  4.   

    使用owner draw必须重载DrawItem,你重载了吗?
      

  5.   

    从CComboBox派生一个类
    然后在CComboBox里面处理
    WM_DRAWITEM消息,是这样的吗?
      

  6.   

    不好意思,写错了,
    是在派生类里面处理WM_DRAWITEM消息,是这样的吗?