MFC Tree Control 绘图刷新异常 20C

添加NM_CUSTOMDRAW响应绘图,运行结果如下图,来回拖动滚动条后,绘制的折线会有部分消失,代码奉上,求高手帮忙看下,多谢!

图片说明

void CTreeViewDlg::OnNMCustomdrawTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
    // TODO: 在此添加控件通知处理程序代码
    LPNMTVCUSTOMDRAW ptvTreeCtrl = (LPNMTVCUSTOMDRAW)pNMHDR;
    if (CDDS_PREPAINT == ptvTreeCtrl->nmcd.dwDrawStage)
    {
        *pResult = CDRF_NOTIFYITEMDRAW;
    }
    else if (CDDS_ITEMPREPAINT == ptvTreeCtrl->nmcd.dwDrawStage)
    {
        HTREEITEM nItem = (HTREEITEM)(ptvTreeCtrl->nmcd.dwItemSpec);
        RECT rcItem;
        m_treeList.GetItemRect(nItem, &rcItem, TRUE);
        if (rcItem.left != rcItem.right && rcItem.top != rcItem.bottom)
        {
            HTREEITEM parentItem = m_treeList.GetParentItem(nItem);
            if (NULL != parentItem)
            {
                for (int i = 0; i < itemInfo.size(); i++)
                {
                    if (nItem == itemInfo[i].m_treeItem)
                    {
                        // 更新当前节点位置
                        int disY = (rcClient.top + rcItem.top + rcItem.bottom) / 2 - itemInfo[i].m_itemPos.y;
                        for (int k = 0; k < itemInfo.size(); k++)
                        {
                            itemInfo[k].m_itemPos.y  +=  disY;
                            if (itemInfo[k].m_type == OutputNode)
                            {
                                itemInfo[k].m_outputInfo.m_turnPos.y += disY;
                                int count = itemInfo[k].m_outputInfo.m_endPos.size();
                                if (count > 0)
                                {
                                    for (int w = 0; w < count; w++)
                                    {
                                        itemInfo[k].m_outputInfo.m_endPos[w].y += disY;
                                    }
                                }
                            }
                        }
                        if (itemInfo[i].m_type == InputNode)
                        {
                            ptvTreeCtrl->clrText = RGB(64, 0, 128);
                        }
                        else
                        {
                            ptvTreeCtrl->clrText = RGB(0, 128, 128);
                            if (itemInfo[i].m_outputInfo.m_endPos.size() > 0&& itemInfo[i].m_itemPos.y>0)
                            {
                                CDC dc;
                                dc.Attach(ptvTreeCtrl->nmcd.hdc);
                                CFont Font;
                                dc.SelectObject(&Font);
                                dc.MoveTo(itemInfo[i].m_itemPos.x, itemInfo[i].m_itemPos.y);
                                dc.LineTo(itemInfo[i].m_outputInfo.m_turnPos.x + 10, itemInfo[i].m_outputInfo.m_turnPos.y);
                                for (int j = 0; j < itemInfo[i].m_outputInfo.m_endPos.size(); j++)
                                {
                                    dc.LineTo(itemInfo[i].m_outputInfo.m_turnPos.x + 10, itemInfo[i].m_outputInfo.m_endPos[j].y);
                                    dc.LineTo(itemInfo[i].m_outputInfo.m_endPos[j].x, itemInfo[i].m_outputInfo.m_endPos[j].y);
                                    DrawArrow(itemInfo[i].m_outputInfo.m_endPos[j], 45, 6, &dc);
                                    dc.MoveTo(itemInfo[i].m_outputInfo.m_turnPos.x + 10, itemInfo[i].m_outputInfo.m_endPos[j].y);
                                }
                                dc.Detach();
                            }
                        }
                        break;
                    }
                }
            }
        }
        *pResult = CDRF_DODEFAULT;
    }
    else if ((CDDS_ITEMPREPAINT | CDDS_SUBITEM) == ptvTreeCtrl->nmcd.dwDrawStage)
    {
        *pResult = CDRF_DODEFAULT;
    }
    return;
}

1个回答

在onscroll里发一个 wm_redraw,让它整个重绘下

hohoa
学-后知不足 滚动条是TreeCtrl的,TreeCtrl没有响应滚动条事件...
9 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!