Declare Function CombineRgn Lib "gdi32.dll" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
CombineRgn combines two regions to form a third region. The two regions can be combined using a variety of logical operators. Note that the region that receives the combined regions must already be a region -- the function cannot create a new one but can change an existing one.
The function returns one of the following flags specifying the result of the region combination operation:
None.
Const ERROR = 0 Const NULLREGION = 1 Const SIMPLEREGION = 2 Const COMPLEXREGION = 3 Const RGN_AND = 1 Const RGN_OR = 2 Const RGN_XOR = 3 Const RGN_DIFF = 4 Const RGN_COPY = 5
' This code is licensed according to the terms and conditions listed here. ' On window Form1, create overlapping elliptical and rectangular regions. ' Fill the overlapped area with a dark gray brush; fill the nonoverlapping areas with ' a light gray brush. Dim hRgn1 As Long, hRgn2 As Long ' elliptical and rectangular source regions. Dim hXorRgn As Long, hAndRgn As Long ' regions set to the non-intersection and intersection Dim hLightBrush As Long, hDarkBrush As Long ' handles to light gray and dark gray brushes Dim retval As Long ' return value ' Create the four regions. The initial settings of hXorRgn and hAndRgn are irrelevant. hRgn1 = CreateEllipticRgn(100, 50, 200, 100) ' bounding rect (100,50)-(200,100) hRgn2 = CreateRectRgn(150, 75, 300, 200) ' rectangle (150,75)-(300,200) hXorRgn = CreateRectRgn(0, 0, 0, 0) ' meaningless initialization hAndRgn = CreateRectRgn(0, 0, 0, 0) ' meaningless initialization ' Now set hAndRgn to the intersection of the two source regions and hXorRgn to ' the non-intersection of the two source regions. retval = CombineRgn(hXorRgn, hRgn1, hRgn2, RGN_XOR) ' non-intersection retval = CombineRgn(hAndRgn, hRgn1, hRgn2, RGN_AND) ' intersection ' Now get the necessary stock brushes and fill in the two combined regions. hLightBrush = GetStockObject(LTGRAY_BRUSH) ' light gray solid brush hDarkBrush = GetStockObject(DKGRAY_BRUSH) ' dark gray solid brush retval = FillRgn(Form1.hDC, hXorRgn, hLightBrush) ' fill non-intersection retval = FillRgn(Form1.hDC, hAndRgn, hDarkBrush) ' fill intersection ' Delete the four regions to free up resources. retval = DeleteObject(hRgn1) retval = DeleteObject(hRgn2) retval = DeleteObject(hXorRgn) retval = DeleteObject(hAndRgn)
Regions
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: December 22, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
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/combinergn.html