Option Explicit
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Const RGN_AND = 1
Private Sub Command1_Click()
Dim hRgn1 As Long
Dim hRgn2 As Long
Dim hRgnIntersect As Long
Dim hBrush As Long
Dim result As Long
Form1.ScaleMode = vbPixels
' Our VB circles
FillStyle = vbSolid
FillColor = vbGreen
Circle (200, 200), 100
FillColor = vbRed
Circle (350, 200), 100
' Now do the clever GDI stuff
hRgnIntersect = CreateRectRgn(0, 0, 0, 0)
hRgn1 = CreateEllipticRgn(100, 100, 300, 300)
hRgn2 = CreateEllipticRgn(250, 100, 450, 300)
result = CombineRgn(hRgnIntersect, hRgn1, hRgn2, RGN_AND)
hBrush = CreateSolidBrush(RGB(255, 255, 0))
FillRgn Form1.hdc, hRgnIntersect, hBrush
' Clean up
DeleteObject hBrush
DeleteObject hRgnIntersect
DeleteObject hRgn2
DeleteObject hRgn1
End Sub