本帖最后由 superlongda 于 2010-08-16 11:01:26 编辑

解决方案 »

  1.   


    void CStringEditListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
    {
    //draw each item.set txt color,bkcolor....
    NMLVCUSTOMDRAW* pNMLVCustomDraw = (NMLVCUSTOMDRAW*)pNMHDR;

    // Take the default processing unless we set this to something else below.
    *pResult = CDRF_DODEFAULT;

    // First thing - check the draw stage. If it's the control's prepaint
    // stage, then tell Windows we want messages for every item.
    if (pNMLVCustomDraw->nmcd.dwDrawStage == CDDS_PREPAINT)
    {
    *pResult = CDRF_NOTIFYITEMDRAW;
    }
    else if (pNMLVCustomDraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
    {
    // This is the notification message for an item.  We'll request
    // notifications before each subitem's prepaint stage.
    *pResult = CDRF_NOTIFYSUBITEMDRAW;
    }
    else if (pNMLVCustomDraw->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM))
    {
    int iItem = (int)pNMLVCustomDraw->nmcd.dwItemSpec;
    int iSubItem = pNMLVCustomDraw->iSubItem;

    CDC* pDC = CDC::FromHandle(pNMLVCustomDraw->nmcd.hdc);

    CString strItemText = GetItemText(iItem, iSubItem);
    CRect rcItem, rcText;
    GetSubItemRect(iItem, iSubItem, LVIR_LABEL, rcItem);
    rcText = rcItem;

    CSize size = pDC->GetTextExtent(strItemText);
    size.cx = GetColumnWidth(iSubItem);
    COLORREF crOldTextColor = pDC->GetTextColor(); if(m_bFocus)
    {

    if((m_nItem == iItem) && (m_nSubItem == iSubItem))
    {
    if(m_bHighLight)
    {
    pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
    pDC->FillSolidRect(&rcText, ::GetSysColor(COLOR_HIGHLIGHT));
    }
    pDC->DrawFocusRect(&rcText);
    }
    } rcItem.left += MOVEEDITTEXTRIGHT;
    pDC->DrawText(strItemText, &rcItem, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOCLIP); pDC->SetTextColor(crOldTextColor); // We've painted everything.
    *pResult = CDRF_SKIPDEFAULT;
    }
    }
      

  2.   

    调试下,可能拖动表头时DrawText文本没被剪裁,或者是没主动刷新。
      

  3.   

    把DT_NOCLIP去掉就不会有图1 列完全叠加显示重叠的效果了 但是还是有内容显示不完全而出现的 "..." ,应该是刷新问题了 不过应该在什么时候刷新呢 
      

  4.   

    问题解决了,else if (pNMLVCustomDraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
    {
    // This is the notification message for an item.  We'll request
    // notifications before each subitem's prepaint stage.
    *pResult = CDRF_NOTIFYSUBITEMDRAW;
    }
    这段代码的问题.