Partager via


CDC::Pie

Draws a pie-shaped wedge by drawing an elliptical arc whose center and two endpoints are joined by lines.

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

Parameters

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

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

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

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

  • x3
    Specifies the x-coordinate of the arc's starting point (in logical units). This point does not have to lie exactly on the arc.

  • y3
    Specifies the y-coordinate of the arc's starting point (in logical units). This point does not have to lie exactly on the arc.

  • x4
    Specifies the x-coordinate of the arc's endpoint (in logical units). This point does not have to lie exactly on the arc.

  • y4
    Specifies the y-coordinate of the arc's endpoint (in logical units). This point does not have to lie exactly on the arc.

  • lpRect
    Specifies the bounding rectangle. You can pass either a CRect object or a pointer to a RECT structure for this parameter.

  • ptStart
    Specifies the starting point of the arc. This point does not have to lie exactly on the arc. You can pass either a POINT structure or a CPoint object for this parameter.

  • ptEnd
    Specifies the endpoint of the arc. This point does not have to lie exactly on the arc. 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 center of the arc is the center of the bounding rectangle specified by x1, y1, x2, and y2 (or by lpRect). The starting and ending points of the arc are specified by x3, y3, x4, and y4 (or by ptStart and ptEnd).

The arc is drawn with the selected pen, moving in a counterclockwise direction. Two additional lines are drawn from each endpoint to the arc's center. The pie-shaped area is filled with the current brush. If x3 equals x4 and y3 equals y4, the result is an ellipse with a single line from the center of the ellipse to the point (x3, y3) or (x4, y4).

The figure drawn by this 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. Both the width and the height of the bounding rectangle must be greater than 2 units and less than 32,767 units.

Example

void CDCView::DrawPie(CDC* pDC)
{
   // Fill the client area with a simple pie chart. A
   // big blue slice covers 75% of the pie, from
   // 6 o'clock to 3 o'clock. This portion is filled
   // with blue and has a blue edge. The remaining 25%
   // is filled with a red, diagonal hatch and has
   // a red edge.

   // 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->Pie(rectClient,
      CPoint(rectClient.right, rectClient.CenterPoint().y),
      CPoint(rectClient.CenterPoint().x, rectClient.right));

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

   // Same parameters, but reverse start and end points.
   pDC->Pie(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

Concepts

CDC Class

CDC Members

Hierarchy Chart

CDC::Chord

Pie

RECT Structure

POINT Structure

CRect Class

CPoint Class