GDI Topics: Polygons |
|
Introduction |
The polylines we have used so far were drawn by defining the starting point of the first line and the end point of the last line. There was no relationship or connection between these two extreme points. A polygon is a closed polyline. In other words, it is a polyline defined so that the end point of the last line is connected to the start point of the first line. To draw a polygon, you can use the TCanvas::Polygon() method. Its syntax is: void __fastcall Polygon(const TPoint * Points, const int Points_Size); This member function uses the same types of arguments as the Polyline() method. The only difference is on the drawing of the line combination. Here is an example: |
If you want to draw a series of polygons, you can use the PolyPolygon() function whose syntax is: BOOL PolyPolygon(HDC hdc, CONST POINT *lpPoints, CONST INT *lpPolyCounts, int nCount); The hdc argument is a handle to the canvas on which you want to draw.
Like the Polygon() method, the lpPoints argument is an array of POINT or
TPoint values. The PolyPolygon() function needs to know the number of polygons you would be drawing. Each polygon uses the points of the
lpPoints value but when creating the array of points, the values must be incremental: each polygon has its own set of points. |
//--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { TPoint Pt[12]; int lpPts[] = { 3, 3, 3, 3 }; // Top Triangle Pt[0] = Point(125, 10); Pt[1] = Point( 95, 70); Pt[2] = Point(155, 70); // Left Triangle Pt[3] = Point( 80, 80); Pt[4] = Point( 20, 110); Pt[5] = Point( 80, 140); // Bottom Triangle Pt[6] = Point( 95, 155); Pt[7] = Point(125, 215); Pt[8] = Point(155, 155); // Right Triangle Pt[9] = Point(170, 80); Pt[10] = Point(170, 140); Pt[11] = Point(230, 110); HDC hDC = Canvas->Handle; PolyPolygon(hDC, Pt, lpPts, 4); } //--------------------------------------------------------------------------- |
Home | Copyright © 2004-2016, FunctionX, Inc. | |