下拉列表框列表中如何显示象word选择线条宽度一样的线条?

解决方案 »

  1.   

    1. 从CListBox派生一个自己的类
    2. 设置LBS_OWNERDRAWFIXED属性
    3. 重载DrawItem,其中自己画线( 也可以画其他东西,总之,发挥你的想象力就可以了)。
      

  2.   

    结贴,顺便把实现过程中的主要的方法DrawItem给大家
    void CColorSelectComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
    // TODO: Add your code to draw the specified item
    if(lpDrawItemStruct->CtlType!=ODT_COMBOBOX)
    return;
    if(lpDrawItemStruct->itemID <0)
    return;
    COLORREF backColor=::GetSysColor(COLOR_WINDOW);//背景色 //包围矩形
    CRect itemRect=lpDrawItemStruct->rcItem;
    CDC *pDC=CDC::FromHandle (lpDrawItemStruct->hDC );
    //设置颜色区域
    CRect colorRect;
    colorRect.left=itemRect.left+COLOR_RECT_BORDER;
    colorRect.top=itemRect.top+COLOR_RECT_BORDER;
    colorRect.right=colorRect.left+COLOR_RECT_WIDTH;
    colorRect.bottom=itemRect.bottom - COLOR_RECT_BORDER;
    //画出颜色区域
    CBrush brush(itemColor);
    CBrush *oldbrush=pDC->SelectObject (&brush);
    pDC->Rectangle (&colorRect);
    pDC->SelectObject (oldbrush);
    }