SetBrushOrgEx Function

Declare Function SetBrushOrgEx Lib "gdi32.dll" (ByVal hdc As Long, ByVal nXOrg As Long, ByVal nYOrg As Long, lppt As POINT_TYPE) As Long

Platforms: Win 32s, Win 95/98, Win NT

SetBrushOrgEx sets the origin point for using a brush on a given device. Note that this function only takes effect on the next brush the device selects -- the currently selected brush in unaffected! The brush origin point determines the offset of the 8x8 block used to fill in areas (the brush). For example, an origin point of (2,3) would shift the fill pattern 2 pixels to the right and 3 pixels downward. The old brush origin point is put into the variable passed as lppt. The function returns 1 if successful, or 0 if an error occured.

hdc
A device context to the device to set the brush origin point of.
nXOrg
The x-coordinate of the new brush origin point. This must be between 0 and 7 inclusive.
nYOrg
The y-coordinate of the new brush origin point. This must be between 0 and 7 inclusive.
lppt
Receives the former brush origin point.

Example:

' Fill in rectange (10,20)-(200,150) on window Form1 with a double diagonal-
' cross hatch pattern: one in green, one in blue.  After the first draw/paint, the brush
' origin is adjusted to make a nice overlay effect.
Dim hbrush As Long  ' receives handle to the brushes the program creates
Dim holdbrush As Long  ' receives handle to the device's default brush
Dim oldorg As POINT_TYPE  ' receives original origin point
Dim xorg As POINT_TYPE  ' throw-away value
Dim retval As Long  ' return value

' ** First, draw the rectangle using the green hatched pattern **
' Create the green hatched brush
hbrush = CreateHatchBrush(HS_DIAGCROSS, RGB(0, 255, 0))
' Set the brush origin point to (0,0) and store the old value (we'll restore it later)
retval = SetBrushOrgEx(Form1.hDC, 0, 0, oldorg)
' Select the hatched brush and create the rectangle
holdbrush = SelectObject(Form1.hDC, hbrush)  ' select the brush
retval = Rectangle(Form1.hDC, 10, 20, 200, 150)  ' make the rectangle
' Restore the default brush temporarily and destroy the hatched brush
retval = SelectObject(Form1.hDC, holdbrush)  ' restore old brush
retval = DeleteObject(hbrush)  ' delete the hatched brush

' ** Now, redraw the rectangle using an offset blue hatched pattern **
' Create the blue hatched brush
hbrush = CreateHatchBrush(HS_DIAGCROSS, RGB(0, 0, 255))
' Set the brush origin point to (4,4) and ignore the old value
retval = SetBrushOrgEx(Form1.hDC, 0, 0, xorg)  ' we don't care about xorg
' Select the hatched brush and recreate the rectangle
holdbrush = SelectObject(Form1.hDC, hbrush)  ' select the brush
retval = Rectangle(Form1.hDC, 10, 20, 200, 150)  ' make the rectangle
' Restore the default brush and destroy the hatched brush
retval = SelectObject(Form1.hDC, holdbrush)  ' restore old brush
retval = DeleteObject(hbrush)  ' delete the hatched brush
' Now, restore the device's old brush origin point
retval = SetBrushOrgEx(Form1.hDC, oldorg.x, oldorg.y, xorg)

See Also: GetBrushOrgEx
Category: Brushes

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
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/s/setbrushorgex.html