CreatePolygonRgn Function

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

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

CreatePolygonRgn creates a polygonal region and provides a handle to it. The polygon is defined by an array of points specifying its vertices. Note that the polygon fill mode must explictly be specified, instead of using the one set for whatever device the region is used with. 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 the polygonal region. Specify each point in order only once.
nCount
The number of elements in the array passed as lpPoint.
nPolyFillMode
Exactly one of the following flags specifying the polygon fill mode to use for the polygonal 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 pixels within a triangular region on window Form1.  The triangular
' region has vertices (150,150), (250, 200), and (100, 200).  Note how the points are loaded
' into the array of vertices. 
Dim vertex(0 To 2) As POINT_TYPE  ' array of region's vertices
Dim hrgn As Long  ' handle to the triangular region
Dim retval As Long  ' return value

' Load the vertices of the triangular region into the array.
vertex(0).x = 150: vertex(0).y = 150  ' 1st point: (150,150)
vertex(1).x = 250: vertex(1).y = 200  ' 2nd point: (250,200)
vertex(2).x = 100: vertex(2).y = 200  ' 3rd point: (100,200)

' Create the polygonal region based on the array of vertices.
hrgn = CreatePolygonRgn(vertex(0), 3, ALTERNATE)  ' for a triangle, fill mode is irrelevant
' Invert the pixels within the triangular region on Form1.
retval = InvertRgn(Form1.hDC, hrgn)
' Delete the region to free up resources.
retval = DeleteObject(hrgn)

See Also: CreatePolyPolygonRgn
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/createpolygonrgn.html