CRgn::CombineRgn

Creates a new GDI region by combining two existing regions.

int CombineRgn( 
   CRgn* pRgn1, 
   CRgn* pRgn2, 
   int nCombineMode  
);

Parameters

  • pRgn1
    Identifies an existing region.

  • pRgn2
    Identifies an existing region.

  • nCombineMode
    Specifies the operation to be performed when combining the two source regions. It can be any one of the following values:

    • RGN_AND   Uses overlapping areas of both regions (intersection).

    • RGN_COPY   Creates a copy of region 1 (identified by pRgn1).

    • RGN_DIFF   Creates a region consisting of the areas of region 1 (identified by pRgn1) that are not part of region 2 (identified by pRgn2).

    • RGN_OR   Combines both regions in their entirety (union).

    • RGN_XOR   Combines both regions but removes overlapping areas.

Return Value

Specifies the type of the resulting region. It can be one of the following values:

  • COMPLEXREGION   New region has overlapping borders.

  • ERROR   No new region created.

  • NULLREGION   New region is empty.

  • SIMPLEREGION   New region has no overlapping borders.

Remarks

The regions are combined as specified by nCombineMode.

The two specified regions are combined, and the resulting region handle is stored in the CRgn object. Thus, whatever region is stored in the CRgn object is replaced by the combined region.

The size of a region is limited to 32,767 by 32,767 logical units or 64K of memory, whichever is smaller.

Use CopyRgn to simply copy one region into another region.

Example

CRgn   rgnA, rgnB, rgnC;

VERIFY(rgnA.CreateRectRgn( 50, 50, 150, 150 ));
VERIFY(rgnB.CreateRectRgn( 100, 100, 200, 200 ));
VERIFY(rgnC.CreateRectRgn( 0, 0, 50, 50 ));

int nCombineResult = rgnC.CombineRgn( &rgnA, &rgnB, RGN_OR );
ASSERT( nCombineResult != ERROR && nCombineResult != NULLREGION );

CBrush br1, br2, br3;
VERIFY(br1.CreateSolidBrush( RGB(255, 0, 0) ));  // rgnA Red
VERIFY(pDC->FrameRgn( &rgnA, &br1, 2, 2 ));
VERIFY(br2.CreateSolidBrush( RGB(0, 255, 0) ));  // rgnB Green
VERIFY(pDC->FrameRgn( &rgnB, &br2, 2, 2 ));
VERIFY(br3.CreateSolidBrush( RGB(0, 0, 255) ));  // rgnC Blue
VERIFY(pDC->FrameRgn( &rgnC, &br3, 2, 2 ));

Requirements

Header: afxwin.h

See Also

Reference

CRgn Class

Hierarchy Chart

CRgn::CopyRgn

CombineRgn

Other Resources

CRgn Members