HRGN CreatePolygonRgn(lppt, cPoints, fnPolyFillMode) | |||||
const POINT FAR* lppt; | /* address of array of points | */ | |||
int cPoints; | /* number of points in array | */ | |||
int fnPolyFillMode; | /* polygon-filling mode | */ |
The CreatePolygonRgn function creates a polygonal region. The system closes the polygon automatically, if necessary, by drawing a line from the last vertex to the first.
lppt
Points to an array of POINT structures. Each structure specifies the x-coordinate and y-coordinate of one vertex of the polygon. The POINT structure has the following form:
typedef struct tagPOINT { /* pt */
int x;
int y;
} POINT;
For a full description of this structure, see the Microsoft Windows Programmer's Reference, Volume 3.
cPoints
Specifies the number of POINT structures in the array pointed to by the lppt parameter.
fnPolyFillMode
Specifies the polygon-filling mode. This value may be either ALTERNATE or WINDING.
The return value is the handle of the region if the function is successful. Otherwise, it is NULL.
The size of a region is limited to 32,767 by 32,767 logical units or 64K of memory, whichever is smaller.
When the polygon-filling mode is ALTERNATE, the system fills the area between odd-numbered and even-numbered polygon sides on each scan line. That is, the system fills the area between the first and second side, between the third and fourth side, and so on.
When the polygon-filling mode is WINDING, the system uses the direction in which a figure was drawn to determine whether to fill an area. Each line segment in a polygon is drawn in either a clockwise or a counterclockwise direction. Whenever an imaginary line drawn from an enclosed area to the outside of a figure passes through a clockwise line segment, the system increments a count (increases it by one); when the line passes through a counterclockwise line segment, the system decrements the count. The area is filled if the count is nonzero when the line reaches the outside of the figure.
When it has finished using a region created by CreatePolygonRgn, an application should remove the region by using the DeleteObject function.
The following example fills an array of POINT structures with the coordinates of a five-pointed star, uses this array in a call to the CreatePolygonRgn function, selects the region into a device context, and then uses the PaintRgn function to display the region:
HDC hdc;
HRGN hrgn;
POINT apts[5] = {{ 200, 10 },
{ 300, 200 },
{ 100, 100 },
{ 300, 100 },
{ 100, 200 }};
hrgn = CreatePolygonRgn(apts, /* array of points */
sizeof(apts) / sizeof(POINT), /* number of points */
ALTERNATE); /* alternate mode */
SelectObject(hdc, hrgn);
PaintRgn(hdc, hrgn);
CreatePolyPolygonRgn, DeleteObject, Polygon, SetPolyFillMode