TBrushEx
Fonte: source/classes/brushex.prg
Standalone class (no inheritance)
TBrushEx creates extended GDI brush objects with gradient patterns. Unlike a standard solid-color brush, TBrushEx generates a bitmap filled with a smooth gradient between two (or four) colors, then creates a pattern brush from that bitmap. This allows windows and controls to be painted with gradient backgrounds without manual gradient drawing code.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
hBrush | Numeric (Handle) | Windows GDI brush handle created from the gradient bitmap |
hBitmap | Numeric (Handle) | Handle to the gradient bitmap that backs the brush |
Methods
| Method | Description |
|---|---|
New( nWidth, nHeight, nColor, nColor2, lVGrad ) | Create a two-color gradient brush. lVGrad is .T. for vertical gradient, .F. (default) for horizontal. |
NewEx( nWidth, nHeight, nC1, nC2, nC3, nC4, lVGrad ) | Create a four-color gradient brush with two additional corner colors for more complex patterns. |
End() | Delete both the brush and the bitmap, releasing all GDI resources. |
Example
#include "FiveWin.ch"
function Main()
local oWnd, oBrush
DEFINE WINDOW oWnd TITLE "TBrushEx Demo" SIZE 400, 300
// Create a horizontal red-to-blue gradient brush
oBrush := TBrushEx():New( 400, 300, CLR_RED, CLR_BLUE, .F. )
oWnd:SetBrush( oBrush )
oWnd:lTransparent := .F.
ACTIVATE WINDOW oWnd CENTERED
oBrush:End()
return nil
Notes
- The bitmap dimensions (
nWidth,nHeight) should match or exceed the area to be filled to avoid tiling artifacts. - Setting
lVGradto .T. creates a vertical gradient (top-to-bottom); .F. creates horizontal (left-to-right). End()must be called when the brush is no longer needed to avoid GDI resource leaks. Both the brush handle and the bitmap handle are deleted internally.- TBrushEx is not derived from any FiveWin base class; it is a lightweight wrapper around
CreaBitmapEx()andCreatePatternBrush()GDI Funções.