[API]
RtlMoveMemory
CreateRectRgn
CombineRgn
Public DeleteObject

[INCLUDE]
UIntAddUInt

[CODE]
#If RegionSet_DebugDraw Then
Public Function RegionSet_ToRegion(ByVal hRegionSet As Long, ByVal OffSet As Long, ByVal Z As Long) As Long
#Else
Public Function RegionSet_ToRegion(ByVal hRegionSet As Long) As Long
#End If
  Dim xByte1 As Byte
  Dim xIntA1(3&) As Integer
  Dim xNumEnts(5) As Integer
  'Dim xType1 As RECT
  Dim xRSetN As Long
  Dim xRSetC As Long
  Dim xLong1 As Long
  Dim HasOnce As Boolean

  If Not hRegionSet = 0& Then
    Call RtlMoveMemory(ByVal VarPtr(xNumEnts(0&)), ByVal hRegionSet, 12&)
    UIntAddUInt hRegionSet, 12&
    For xLong1 = 1& To xNumEnts(0&)
      Call RtlMoveMemory(ByVal VarPtr(xByte1), ByVal hRegionSet, 1&)
      UIntAddUInt hRegionSet, 1&
      Call RtlMoveMemory(ByVal VarPtr(xIntA1(0)), ByVal hRegionSet, 8&)
      UIntAddUInt hRegionSet, 8&
      xRSetN = CreateRectRgn(xIntA1(0&), xIntA1(1&), xIntA1(2&), xIntA1(3&))
      If xRSetN = 0& Then GoTo DoExitC
      If HasOnce Then
        If CombineRgn(xRSetC, xRSetC, xRSetN, xByte1) = 0& Then
          GoTo DoExitCN
          End If
        Call DeleteObject(xRSetN)
        Else
        xRSetC = xRSetN
        HasOnce = True
        End If
#If RegionSet_DebugDraw Then
Dim xAdditive As Long

xAdditive = (4& - xByte1) / 2&
      RegionSetDebugCol = (RegionSetDebugCol + 1&) Mod 8
'Stop
      Form1.Picture2.Line (xIntA1(0) * Z + OffSet, xIntA1(1) * Z)-((xIntA1(2) - 1) * Z + Z - 1 + OffSet, (xIntA1(3) - 1) * Z + Z - 1), Fix(RegionSetDebugCol * 127 / 8& + 128) * (xAdditive * &HFF& + 1&), BF
      Form1.Picture2.Picture = Form1.Picture2.Image
      DoEventsEx_SleepPeriodical

#End If
      Next
    
    'Stop
    For xByte1 = 0& To 4&
      For xLong1 = 1& To xNumEnts(xByte1 + 1&)
        Call RtlMoveMemory(ByVal VarPtr(xIntA1(0)), ByVal hRegionSet, 4&)
        UIntAddUInt hRegionSet, 4&
        xRSetN = CreateRectRgn(xIntA1(0&), xIntA1(1&), xIntA1(0&) + 1&, xIntA1(1&) + 1&)
        If xRSetN = 0& Then GoTo DoExitC
        If HasOnce Then
          If CombineRgn(xRSetC, xRSetC, xRSetN, xByte1) = 0& Then
            GoTo DoExitCN
            End If
          Call DeleteObject(xRSetN)
          Else
          xRSetC = xRSetN
          HasOnce = True
          End If
  
#If RegionSet_DebugDraw Then
  'Dim xAdditive As Long
  
xAdditive = (4& - xByte1) / 2&
        RegionSetDebugCol = (RegionSetDebugCol + 1&) Mod 8
  'Stop
        Form1.Picture2.Line (xIntA1(0) * Z + OffSet, xIntA1(1) * Z)-((xIntA1(0)) * Z + Z - 1 + OffSet, (xIntA1(1)) * Z + Z - 1), Fix(RegionSetDebugCol * 63 / 8& + 64) * (xAdditive * &HFF& + 1&), BF
        Form1.Picture2.Picture = Form1.Picture2.Image
        DoEventsEx_SleepPeriodical
  
#End If
        Next
      Next
'Stop
    RegionSet_ToRegion = xRSetC
'    Stop
    GoTo DoExit

    'Call SetWindowRgn(hWnd, xRSetC, True)
DoExitCN:
    If Not xRSetN = 0& Then Call DeleteObject(xRSetN)
DoExitC:
    If Not xRSetC = 0& Then Call DeleteObject(xRSetC)
DoExit:
    End If
  End Function

