CreatePolyPolygonRgn Function

Declare Function CreatePolyPolygonRgn Lib "gdi32.dll" (lpPoint As POINT_TYPE, lpPolyCounts As Long, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long

Platforms: Win 32s, Win 95/98, Win NT

CreatePolyPolygonRgn creates a region consisting of multiple polygons. The vertices of all the polygons are passed to the function in the array passed as lpPoint. Another array specifies how many points within that array belong to each polygon. The individual polygons are not joined in any way, forming a region of multiple unconnected polygonal areas. Note that the fill mode for the multi-polygonal region must be specified explicitly, instead of using the filling mode set for whatever device the region is used on. The function returns the handle to the newly created region if successful, or 0 if an error occured.

lpPoint
An array holding the vertices of every polygon making up the new region. Specify each point for each polygon only once. See the example for a demonstration of how to load multiple polygons into this array.
lpPolyCounts
An array specifying how many vertices in the array passed as lpPoint belong to each polygon.
nCount
The number of elements in the array passed as lpPolyCounts.
nPolyFillMode
Exactly one of the following flags specifying the fill mode used for each polygon within the region:
ALTERNATE = 1
Alternates between filling and not filling contiguous sections whose boundaries are determined by the edge(s) of the polygon crossing through the polygon's interior.
WINDING = 2
Any section inside the polygon is filled, regardless of any intra-polygonal boundaries and edges.

Example:

' Invert the points lying within a multi-polygonal region on window Form1.  The
' region is made up of a triangle and a diamond.  The triangle has vertices (25,25), (50,50),
' and (25,50).  The diamond has vertices (150,150), (200,200), (150,250), and (100,200).

Dim vertex(0 To 6) As POINT_TYPE ' holds vertices of each polygon
Dim numvertices(0 To 1) As Long  ' holds how many vertices belong to each polygon
Dim hrgn As Long  ' handle to the multi-polygonal region
Dim retval As Long  ' return value

' Load the vertices of the triangle into the vertex array.
vertex(0).x = 25: vertex(0).y = 25  ' 1st point: (25,25)
vertex(1).x = 50: vertex(1).y = 50  ' 2nd point: (50,50)
vertex(2).x = 25: vertex(2).y = 50  ' 3rd point: (25,50)
numvertices(0) = 3  ' three vertices for the triangle

' Load the vertices of the diamond into the vertex array.
vertex(3).x = 150: vertex(3).y = 150  ' 1st point: (150,150)
vertex(4).x = 200: vertex(4).y = 200  ' 2nd point: (200,200)
vertex(5).x = 150: vertex(5).y = 250  ' 3rd point: (150,250)
vertex(6).x = 100: vertex(6).y = 200  ' 4th point: (100,200)
numvertices(1) = 4  ' four vertices for the triangle

' Create the multi-polygonal region and get a handle to it.
hrgn = CreatePolyPolygonRgn(vertex(0), numvertices(0), 2, ALTERNATE)
' Invert the pixels within this region on Form1.
retval = InvertRgn(Form1.hDC, hrgn)
' Delete the region to free up resources.
retval = DeleteObject(hrgn)

See Also: CreatePolygonRgn
Category: Regions

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/c/createpolypolygonrgn.html