OffsetRgn

2.x

  int OffsetRgn(hrgn, nXOffset, nYOffset)    
  HRGN hrgn; /* handle of region, */  
  int nXOffset; /* offset along x-axis, */  
  int nYOffset; /* offset along y-axis, */  

The OffsetRgn function moves the given region by the specified offsets.

Parameters

hrgn

Identifies the region to be moved.

nXOffset

Specifies the number of logical units to move left or right.

nYOffset

Specifies the number of logical units to move up or down.

Return Value

The return value is SIMPLEREGION (region has no overlapping borders), COMPLEXREGION (region has overlapping borders), or NULLREGION (region is empty), if the function is successful. Otherwise, the return value is ERROR.

Comments

The coordinate values of a region must not be greater than 32,767 or less than –32,768. The nXOffset and nYOffset parameters must be carefully chosen to prevent invalid regions.

Example

The following example creates a rectangular region, uses the OffsetRgn function to move the region 50 positive units in the x- and y-directions, selects the offset region into the device context, and then fills it by using a blue brush:

HDC hdcLocal;
HRGN hrgn;
HBRUSH hbrBlue;
int RgnType;

hdcLocal = GetDC(hwnd);
hrgn = CreateRectRgn(100, 10, 210, 110);
SelectObject(hdc, hrgn);
PaintRgn(hdc, hrgn);

RgnType = OffsetRgn(hrgn, 50, 50);
SelectObject(hdc, hrgn);

if (RgnType == ERROR)
    TextOut(hdcLocal, 10, 135, "ERROR", 5);
else if (RgnType == SIMPLEREGION)
    TextOut(hdcLocal, 10, 135, "SIMPLEREGION", 12);
else if (RgnType == NULLREGION)
    TextOut(hdcLocal, 10, 135, "NULLREGION", 10);
else
    TextOut(hdcLocal, 10, 135, "Unrecognized value.", 19);

hbrBlue = CreateSolidBrush(RGB(0, 0, 255));
FillRgn(hdc, hrgn, hbrBlue);

DeleteObject(hrgn);
DeleteObject(hbrBlue);
ReleaseDC(hwnd, hdcLocal);