• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetPenBrushFill

Started by José Roca, July 02, 2008, 11:25:15 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a Brush object, creates a Pen object based on the Brush object, draws a line with the pen, gets the Brush from the pen, and then uses the Brush to fill a rectangle.

C++


VOID Example_GetBrush(HDC hdc)
{
   Graphics graphics(hdc);

    HatchBrush hatchBrush(
      HatchStyleVertical,
      Color(255, 255, 0, 0),   // red
      Color(255, 0, 0, 255));  // blue

   // Create a pen based on a hatch brush, and use that pen
   // to draw a line.
   Pen pen(&hatchBrush, 15);
   graphics.DrawLine(&pen, 0, 0, 200, 100);

   // Get the pen's brush, and use that brush to fill a rectangle.
   Brush* pBrush = pen.GetBrush();
   graphics.FillRectangle(pBrush, 0, 100, 200, 100);
}


PowerBASIC


SUB GDIP_GetPenBrushFill (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
   LOCAL pBrush 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 based on a hatch brush, and use that pen to draw a line.
   hStatus = GdipCreatePen2(pHatchBrush, 15, %UnitWorld, pPen)
   hStatus = GdipDrawLineI(pGraphics, pPen, 0, 0, 200, 100)

   ' // Get the pen's brush, and use that brush to fill a rectangle.
   hStatus = GdipGetPenBrushFill(pPen, pBrush)
   hStatus = GdipFillRectangleI(pGraphics, pBrush, 0, 100, 200, 100)

   ' // Cleanup
   IF pPen THEN GdipDeletePen(pPen)
   IF pBrush THEN GdipDeleteBrush(pBrush)
   IF pHatchBrush THEN GdipDeleteBrush(pHatchBrush)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB