다음을 통해 공유


CDC::Chord

Draws a chord (a closed figure bounded by the intersection of an ellipse and a line segment).

BOOL Chord( 
   int x1, 
   int y1, 
   int x2, 
   int y2, 
   int x3, 
   int y3, 
   int x4, 
   int y4  
); 
BOOL Chord( 
   LPCRECT lpRect, 
   POINT ptStart, 
   POINT ptEnd  
);

Parameters

  • x1
    Specifies the x-coordinate of the upper-left corner of the chord's bounding rectangle (in logical units).

  • y1
    Specifies the y-coordinate of the upper-left corner of the chord's bounding rectangle (in logical units).

  • x2
    Specifies the x-coordinate of the lower-right corner of the chord's bounding rectangle (in logical units).

  • y2
    Specifies the y-coordinate of the lower-right corner of the chord's bounding rectangle (in logical units).

  • x3
    Specifies the x-coordinate of the point that defines the chord's starting point (in logical units).

  • y3
    Specifies the y-coordinate of the point that defines the chord's starting point (in logical units).

  • x4
    Specifies the x-coordinate of the point that defines the chord's endpoint (in logical units).

  • y4
    Specifies the y-coordinate of the point that defines the chord's endpoint (in logical units).

  • lpRect
    Specifies the bounding rectangle (in logical units). You can pass either a LPRECT or a CRect object for this parameter.

  • ptStart
    Specifies the x- and y-coordinates of the point that defines the chord's starting point (in logical units). This point does not have to lie exactly on the chord. You can pass either a POINT structure or a CPoint object for this parameter.

  • ptEnd
    Specifies the x- and y-coordinates of the point that defines the chord's ending point (in logical units). This point does not have to lie exactly on the chord. You can pass either a POINT structure or a CPoint object for this parameter.

Return Value

Nonzero if the function is successful; otherwise 0.

Remarks

The (x1, y1) and (x2, y2) parameters specify the upper-left and lower-right corners, respectively, of a rectangle bounding the ellipse that is part of the chord. The (x3, y3) and (x4, y4) parameters specify the endpoints of a line that intersects the ellipse. The chord is drawn by using the selected pen and filled by using the selected brush.

The figure drawn by the Chord function extends up to, but does not include the right and bottom coordinates. This means that the height of the figure is y2 – y1 and the width of the figure is x2 – x1.

Example

void CDCView::DrawChord(CDC* pDC)
{
   // Fill the client area with a circle. The circle is 
   // blue and filled with blue, but has a chord cut out 
   // of it from 3 o'clock to 6 o'clock. That chord is 
   // red and filled with a red diagonal hatch. 

   // Get the client area.
   CRect rectClient;
   GetClientRect(rectClient);

   // Make a couple of pens and similar brushes.
   CPen penBlue, penRed;
   CBrush brushBlue, brushRed;
   CBrush* pOldBrush;
   CPen* pOldPen;

   brushBlue.CreateSolidBrush(RGB(0, 0, 255));
   brushRed.CreateHatchBrush(HS_FDIAGONAL, RGB(255, 0, 0));
   penBlue.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(0, 0, 255));
   penRed.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(255, 0, 0));

   // Draw from 3 o'clock to 6 o'clock, counterclockwise, 
   // in a blue pen with a solid blue fill.
   pOldPen = pDC->SelectObject(&penBlue);
   pOldBrush = pDC->SelectObject(&brushBlue);

   pDC->Chord(rectClient,
      CPoint(rectClient.right, rectClient.CenterPoint().y),
      CPoint(rectClient.CenterPoint().x, rectClient.right));

   // Draw the remaining quarter chord from 6 o'clock 
   // to 3 o'clock, counterclockwise, in a red pen 
   // with the hatched brush.
   pDC->SelectObject(&penRed);
   pDC->SelectObject(&brushRed);

   // Keep the same parameters, but reverse start and 
   // end points.
   pDC->Chord(rectClient,
      CPoint(rectClient.CenterPoint().x, rectClient.right),
      CPoint(rectClient.right, rectClient.CenterPoint().y));

   // Restore the previous pen.
   pDC->SelectObject(pOldPen);
}

Requirements

Header: afxwin.h

See Also

Reference

CDC Class

Hierarchy Chart

CDC::Arc

Chord

POINT Structure