class CComboBox_Ex : public CComboBox
……void CComboBox_Ex::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
   ASSERT(lpDrawItemStruct->CtlType == ODT_COMBOBOX);
   LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
   //……这里的lpzsText是乱码
}为什么把ListBox资源的Has strings选上运行会报错?

解决方案 »

  1.   

    这里有解释,Has strings选上的时候,itemData的值是零,需要你自己用SetItemData设定itemData
    Specifies the application-defined value associated with the menu item. For a control, this parameter specifies the value last assigned to the list box or combo box by the LB_SETITEMDATA or CB_SETITEMDATA message. If the list box or combo box has the LBS_HASSTRINGS or CBS_HASSTRINGS style, this value is initially zero. Otherwise, this value is initially the value that was passed to the list box or combo box in the lParam parameter of one of the following messages: 
    CB_ADDSTRING
    CB_INSERTSTRING
    LB_ADDSTRING
    LB_INSERTSTRING你的string 是怎么加进去的?
      

  2.   

    http://www.vchelp.net/vchelp/file2002_3/color_combo.asp?type_id=3&class_id=1&cata_id=1&article_id=833自己看吧~~~~~~
      

  3.   

    to kingtsui(老农民) :
    我是用AddString加的
      

  4.   

    把AddString这一行贴出来看看
    再判断一下AddString的返回值,看看有没有出错
    补充一点,如果用了AddString而要在DrawItem里用的话,就不应该调用SetItemData,因为这样的话itmeData的值就成了SetItemData里设定的值了,而不是AddString里加入的字符串了
      

  5.   

    to kingtsui(老农民) :
    CComboBox comboTest;
    CString str = _T("abc");
    comboTest.AddString(str);其实我是想通过重画下拉选项,使得那些项长度大于下拉框宽度的能延伸到框外面显示出来。
    可是这样做好像行不通,应该怎么来实现呢?