如何在combobox中加入不同类型的线条

解决方案 »

  1.   

    是不是还得重载DrawItem,还得处理WM_DRAWITEM,可是不知道如何具体实现啊 
      

  2.   

    百度吧,网上重绘combobox的示例多的很
      

  3.   


    void CShowComboBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)  
    {
    // TODO: Add your code to determine the size of specified item
    lpMeasureItemStruct->itemHeight = CComboBox::GetItemHeight(0);
    }void CShowComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) //combobo
    {
    // TODO: Add your code to draw the specified item
      CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
    int nSaveDC=pDC->SaveDC();
    CRect itemRect = lpDrawItemStruct->rcItem;
    int nItem = lpDrawItemStruct->itemID;
        
    if(lpDrawItemStruct->itemAction & ODA_DRAWENTIRE)
    {
      DrawItemBk(pDC,itemRect,nItem, CS_NORMAL); //画正常状态item的背景
      DrawItemImage(pDC,itemRect,nItem,GetItemImage(nItem),CS_NORMAL);  
    DrawItemText(pDC,itemRect,nItem,CS_NORMAL);//画正常状态item文if(!GetItemDisable(nItem))  
    {
    DrawItemBk(pDC,itemRect,nItem,CS_DISABLED);
    DrawItemImage(pDC,itemRect,nItem,GetItemImage(nItem),CS_DISABLED);
    DrawItemText(pDC,itemRect,nItem,CS_DISABLED);
    }
    }if((lpDrawItemStruct->itemState & ODS_SELECTED) &&  
    (lpDrawItemStruct->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) )
    {
    DrawItemBk(pDC,itemRect,nItem,CS_HOT);
    DrawItemImage(pDC,itemRect,nItem,GetItemImage(nItem),CS_HOT);
    DrawItemText(pDC,itemRect,nItem,CS_HOT);
    }if(!(lpDrawItemStruct->itemState & ODS_SELECTED) &&  
    (lpDrawItemStruct->itemAction & ODA_SELECT ) )
    {
    DrawItemBk(pDC,itemRect,nItem,CS_SELECT);
    DrawItemImage(pDC,itemRect,nItem,GetItemImage(nItem),CS_SELECT);
    DrawItemText(pDC,itemRect,nItem,CS_SELECT);
    }pDC->RestoreDC(nSaveDC);
    }void CShowComboBox::OnPaint(),多处理OnPaint主要是处理edit/static的部分,上边的drawitem是只能处理list中的.
    {
    CPaintDC dc(this); // device context for painting
    CRect rectBk;
    GetClientRect(rectBk);DrawBorder(&dc,rectBk,GetComboState());
    DrawBackGround(&dc,rectBk,GetComboState());
    DrawDownButton(&dc,rectBk,GetComboState()); //与按钮一样,有正常,HOT,按下和非激活状态if ( CComboBox::GetCount() >0 && CComboBox::GetCurSel() >= 0 )

    int nState = CS_NORMAL;
    int nItem = CComboBox::GetCurSel();
    GetComboState()== CS_SELECT ? nState = CS_DISABLED : nState = CS_NORMAL ;
    CString strItemText = "" ;
    GetLBText(nItem,strItemText);
    DrawItemText(&dc,rectBk,nItem,strItemText,nState);
    DrawItemImage(&dc,rectBk,nItem,GetItemImage(nItem),nState);
    }
    }
    由于,设置重绘的combobox,在EDIT/STATIC的部分,高度很难看,所以可以用CComboBox::SetItemHeight(-1, 13)来设置一下可以放在PreSubclassWindow中,不然太高了,难看.可以扩展,下拉列表框带列头, 支持多列,支持disiable等.稍做变动便可.