The following example creates a
CustomLineCap with a stroke path, creates a second
CustomLineCap by cloning the first, and then assigns the cloned cap to a
Pen. It then draws a line by using the
Pen.
C++
VOID Example_Clone(HDC hdc)
{
Graphics graphics(hdc);
//Create a Path, and add two lines to it.
Point points[3] = {Point(-15, -15), Point(0, 0), Point(15, -15)};
GraphicsPath capPath(FillModeAlternate);
capPath.AddLines(points, 3);
// Create a CustomLineCap object.
CustomLineCap firstCap(NULL, &capPath);
// Create a copy of firstCap.
CustomLineCap * secondCap = firstCap.Clone();
// Create a Pen object, assign second cap as the custom end cap, and
// draw a line.
Pen pen(Color(255, 0, 0, 0), 1);
pen.SetCustomEndCap(secondCap);
graphics.DrawLine(&pen, Point(0, 0), Point(100, 100));
}
PowerBASIC
SUB GDIP_CloneCustomLineCap (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pCapPath AS DWORD
LOCAL pFirstCap AS DWORD
LOCAL pSecondCap AS DWORD
LOCAL pPen AS DWORD
DIM PointsF(2) AS POINTF
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create a path and add two lines to it.
PointsF(0).x = -15 : PointsF(0).y = -15
PointsF(1).x = 0 : PointsF(1).y = 0
PointsF(2).x = 15 : PointsF(2).y = -15
hStatus = GdipCreatePath(%FillModeAlternate, pCapPath)
hStatus = GdipAddPathLine2(pCapPath, PointsF(0), 3)
' // Create a CustomLineCap
hStatus = GdipCreateCustomLineCap(%NULL, pCapPath, %LineCapFlat, 0, pFirstCap)
' // Create a copy of FirstCap
hStatus = GdipCloneCustomLineCap(pFirstCap, pSecondCap)
' // Create a Pen, assignd SecondCap as the custom end cap, and draw the line
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1.0!, %UnitWorld, pPen)
hStatus = GdipSetPenCustomEndCap(pPen, pSecondCap)
' // Draw a line using arrowPen.
hStatus = GdipDrawLineI(pGraphics, pPen, 0, 0, 100, 100)
' // Cleanup
IF pSecondCap THEN GdipDeleteCustomLineCap(pSecondCap)
IF pFirstCap THEN GdipDeleteCustomLineCap(pFirstCap)
IF pPen THEN GdipDeletePen(pPen)
IF pCapPath THEN GdipDeletePath(pCapPath)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipCloneCustomLineCap.png)