int CombineRgn(hrgnDest, hrgnSrc1, hrgnSrc2, fCombineMode) | |||||
HRGN hrgnDest; | /* handle of region to receive combined regions | */ | |||
HRGN hrgnSrc1; | /* handle of first source region | */ | |||
HRGN hrgnSrc2; | /* handle of second source region | */ | |||
int fCombineMode; | /* mode for combining regions | */ |
The CombineRgn function creates a new region by combining two existing regions.
hrgnDest
Identifies an existing region that will be replaced by the new region.
hrgnSrc1
Identifies an existing region.
hrgnSrc2
Identifies an existing region.
fCombineMode
Specifies the operation to use when combining the two source regions. This parameter can be any one of the following values:
Value | Meaning |
RGN_AND | Uses overlapping areas of both regions (intersection). |
RGN_COPY | Creates a copy of region 1 (identified by the hrgnSrc1 parameter). |
RGN_DIFF | Creates a region consisting of the areas of region 1 (identified by hrgnSrc1) that are not part of region 2 (identified by the hrgnSrc2 parameter). |
RGN_OR | Combines all of both regions (union). |
RGN_XOR | Combines both regions but removes overlapping areas. |
The return value specifies that the resulting region has overlapping borders (COMPLEXREGION), is empty (NULLREGION), or has no overlapping borders (SIMPLEREGION), if the function is successful. Otherwise, the return value is ERROR.
The size of a region is limited to 32,000 by 32,000 logical units or 64K of memory, whichever is smaller.
The CombineRgn function replaces the region identified by the hrgnDest parameter with the combined region. To use CombineRgn most efficiently, hrgnDest should be a trivial region, as shown in the following example.
The following example creates two source regions and an empty destination region, uses the CombineRgn function to create a complex region, selects the region into a device context, and then uses the PaintRgn function to display the region:
HDC hdc;
HRGN hrgnDest, hrgnSrc1, hrgnSrc2;
hrgnDest = CreateRectRgn(0, 0, 0, 0);
hrgnSrc1 = CreateRectRgn(10, 10, 110, 110);
hrgnSrc2 = CreateRectRgn(90, 90, 200, 150);
CombineRgn(hrgnDest, hrgnSrc1, hrgnSrc2, RGN_OR);
SelectObject(hdc, hrgnDest);
PaintRgn(hdc, hrgnDest);