2007년 4월 8일 일요일

GDI+ line/polygon/curve

먼저 GDI+ 를 사용하기 위한 기본 설정은
For the proper use of GDI+ refer

    Using GDI+ in VS.NET 2005
    
를 참조한다.


1. Lines

void CGdiplusDemoView::OnDraw(CDC* pDC)
{
    Graphics g(pDC->m_hDC);
    Pen pen(Color(255, 0, 0, 0), 3);        // Pen with thickness = 3

    g.DrawLine(&pen, 50, 50, 500, 50);
    g.DrawRectangle(&pen, 50, 100, 200, 100);
    g.DrawEllipse(&pen, 300, 100, 200, 100);
    g.DrawPie(&pen, 50, 250, 200, 200, 225, 90);
    g.DrawArc(&pen, 300, 250, 200, 200, 225, 90);
}

2. Polygon and curves

void CGdiplusDemoView::OnDraw(CDC* pDC)
{
    Graphics g(pDC->m_hDC);
    Pen pen(Color(255, 0, 0, 0), 3);

    // Set coordinates
    Point points[] = {
        Point(30, 30), Point(120, 50), Point(170, 10), Point(150, 90), Point(90, 70), Point(50, 130)
    };

    // Polygon
    g.DrawPolygon(&pen, points, 6);
    
    // Closed curve
    for ( int i = 0; i < 6; i++ )
        points[i].X += 200;
    g.DrawClosedCurve(&pen, points, 6, 0.5f);

    // Closed curve
    for ( int i = 0; i < 6; i++ )
        points[i].X += 200;
    g.DrawClosedCurve(&pen, points, 6, 1);

    // Opened curve
    for ( int i = 0; i < 6; i++ ) {
        points[i].X -= 400;
        points[i].Y += 150;
    }
    g.DrawCurve(&pen, points, 6, 0);

    // Opened curve
    for ( int i = 0; i < 6; i++ )
        points[i].X += 200;
    g.DrawCurve(&pen, points, 6, 0.5);

    // Opend curve
    for ( int i = 0; i < 6; i++ )
        points[i].X += 200;
    g.DrawCurve(&pen, points, 6, 1);
}


댓글 없음: