• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipClonePen

Started by José Roca, July 01, 2008, 10:07:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a Pen object, creates a copy of the Pen object, and then draws an ellipse using the copied Pen object.

C++


VOID Example_Clone(HDC hdc)
{
   Graphics graphics(hdc);
   
   // Create and clone a Pen object.
   Pen pen(Color(255, 0, 0, 255), 4);
   Pen* pPen = pen.Clone();

   // Draw a rectangle using the cloned Pen object.
   graphics.DrawRectangle(pPen, 10, 10, 100, 50);

   delete pPen;
}


PowerBASIC


SUB GDIP_ClonePen (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPen AS DWORD
   LOCAL pClonedPen AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create and clone a Pen object.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 255), 4, %UnitWorld, pPen)
   hStatus = GdipClonePen(pPen, pClonedPen)

   ' // Draw a rectangle using the cloned Pen object.
   hStatus = GdipDrawRectangleI(pGraphics, pClonedPen, 10, 10, 100, 50)

   ' // Cleanup
   IF pPen THEN GdipDeletePen(pPen)
   IF pClonedPen THEN GdipDeletePen(pClonedPen)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB


The following illustration shows the output of the preceding code.