如何填充矩形(c ++,mfc)

时间:2016-09-10 21:49:37

标签: c++ visual-studio mfc 2d draw

我需要填充“矩形”(diagonall filling)enter image description here的部分(如此图片所示)。 如何在mfc上做到这一点?抱歉我的英文不好!

void CKonokhovView::OnLButtonUp(UINT nFlags, CPoint point)
{
if (m_Dragging){
    m_Dragging = 0;
    ::ReleaseCapture();
    ::ClipCursor(NULL);
    CKonokhovDoc* pDoc = GetDocument();
    CClientDC ClientDC(this);
    CPen pen;
    pen.CreatePen(PS_SOLID, 1, pDoc->docColor);
    ClientDC.SelectObject(&pen);
    ClientDC.SetROP2(R2_NOT);
    ClientDC.Rectangle(m_PointOrigin.x, m_PointOrigin.y, m_PointOld.x,      m_PointOld.y);
    ClientDC.SetROP2(R2_COPYPEN);
    CBrush* oldBrush = ClientDC.SelectObject(&nullBrush);
    ClientDC.Rectangle(m_PointOrigin.x, m_PointOrigin.y, point.x, point.y);

    pDoc->AddLine(m_PointOrigin.x, m_PointOrigin.y, point.x, point.y);
    ClientDC.SelectObject(&oldBrush);


}

1 个答案:

答案 0 :(得分:3)

您可以使用CDC::Polygon,这是Polygon API

的包装器

示例:

CRect rc(0, 0, 100, 100);
CPoint points[3];
points[0] = CPoint(rc.left, rc.top);
points[1] = CPoint(rc.right, rc.top);
points[2] = CPoint(rc.left, rc.bottom);

ClientDC.Polygon(points, 3);