The following example creates a
HatchBrush object and then passes the address of that
HatchBrush object to a
Pen constructor. The code then sets the brush for the pen and draws a line.
C++
VOID Example_SetBrush(HDC hdc)
{
Graphics graphics(hdc);
// Create a HatchBrush object.
HatchBrush hatchBrush(
HatchStyleVertical,
Color(255, 255, 0, 0), // red
Color(255, 0, 0, 255)); // blue
// Create a pen, and set the brush for the pen.
Pen pen(Color(255, 255, 0, 0), 10);
pen.SetBrush(&hatchBrush);
// Draw a line with the pen.
graphics.DrawLine(&pen, 0, 0, 200, 100);
}
PowerBASIC
SUB GDIP_SetPenBrushFill (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pColorRed AS DWORD
LOCAL pColorBlue AS DWORD
LOCAL pPen AS DWORD
LOCAL pHatchBrush AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Set colors.
pColorRed = GDIP_ARGB(255, 255, 0, 0)
pColorBlue = GDIP_ARGB(255, 0, 0, 255)
' // Create a HatchBrush object.
hStatus = GdipCreateHatchBrush(%HatchStyleHorizontal, pColorRed, pColorBlue, pHatchBrush)
' // Create a pen, and set the brush for the pen.
hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 10, %UnitWorld, pPen)
hStatus = GdipSetPenBrushFill(pPen, pHatchBrush)
' // Draw a line with the pen.
hStatus = GdipDrawLineI(pGraphics, pPen, 0, 0, 200, 100)
' // Cleanup
IF pPen THEN GdipDeletePen(pPen)
IF pHatchBrush THEN GdipDeleteBrush(pHatchBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
The following illustration shows the output of the preceding code.
(http://www.jose.it-berater.org/captures/GdipSetPenBrushFill.png)