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.
(http://www.jose.it-berater.org/captures/GdipClonePen.png)