Private Type POINTAPI
        x As Long
        y As Long
End Type
Private Declare Function CreatePolyPolygonRgn Lib "gdi32" (lpPoint As POINTAPI, lpPolyCounts As Long, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function InvertRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Sub Form_Load()
    Me.AutoRedraw = True
    ' 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 POINTAPI ' 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(Me.hdc, hRgn)
    ' Delete the region to free up resources.
    retval = DeleteObject(hRgn)
End Sub

解决方案 »

  1.   

    【函数】
    CreatePolyPolygonRgn【操作系统】
    Win9X:Yes
    WinNT:Yes【声明】
    CreatePolyPolygonRgn Lib "gdi32" Alias "CreatePolyPolygonRgn" (lpPoint As POINTAPI, lpPolyCounts As Long, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long【说明】  创建由多个多边形构成的区域。每个多边形都应是封闭的 【返回值】  Long,执行成功则为创建区域的句柄,失败则为零 【其它】  不用时一定要用DeleteObject函数删除该区域【参数表】
      lpPoint --------  POINTAPI,nCount个POINTAPI结构中的第一个POINTAPI结构  lpPolyCounts ---  Long,长整数阵列的第一个入口。每个入口包含构成一个封闭多边形的点数。lpPoint阵列组成了一系列多边形,每个多边形在lpPolyCounts中有一个入口  nCount ---------  Long,多边形的点数  nPolyFillMode --  Long,描述多边形填充模式。可为ALTERNATE 或 WINDING常数。参考SetPolyFillMode函数对多边形填充模式的解释