SetBrushOrg

2.x

  DWORD SetBrushOrg(hdc, nXOrg, nYOrg)    
  HDC hdc; /* handle of device context */
  int nXOrg; /* x-coordinate of new origin */
  int nYOrg; /* y-coordinate of new origin */

The SetBrushOrg function specifies the origin that GDI will assign to the next brush an application selects into the specified device context.

Parameters

hdc

Identifies the device context.

nXOrg

Specifies the x-coordinate, in device units, of the new origin. This value must be in the range 0 through 7.

nYOrg

Specifies the y-coordinate, in device units, of the new origin. This value must be in the range 0 through 7.

Return Value

The return value is the coordinates, in device units, of the previous origin, if the function is successful. The low-order word contains the x-coordinate; the high-order word contains the y-coordinate.

Comments

The default coordinates for the brush origin are (0, 0).

To alter the origin of a brush, an application should call the UnrealizeObject function, specifying the handle of the brush for which the origin will be set; call SetBrushOrg; and then call the SelectObject function to select the brush into the device context.

The SetBrushOrg function should not be used with stock objects.

Example

The following example uses the SetBrushOrg function to shift the brush origin vertically by 5 pixels:

HBRUSH hbr, hbrOld;
SetBkMode(hdc, TRANSPARENT);
hbr = CreateHatchBrush(HS_CROSS, RGB(0, 0, 0));

UnrealizeObject(hbr);
SetBrushOrg(hdc, 0, 0);
hbrOld = SelectObject(hdc, hbr);

Rectangle(hdc, 0, 0, 200, 200);

hbr = SelectObject(hdc, hbrOld);              /* deselects hbr */
UnrealizeObject(hbr);  /* resets origin next time hbr selected */
SetBrushOrg(hdc, 3, 5);
hbrOld = SelectObject(hdc, hbr);          /* selects hbr again */

Rectangle(hdc, 0, 0, 200, 200);

SelectObject(hdc, hbrOld);
DeleteObject(hbr);

See Also

GetBrushOrg, SelectObject, UnrealizeObject