The following example creates a
CustomLineCap and sets the width scale. It then assigns the custom cap to a
Pen, and draws a line.
C++
VOID Example_SetWidthScale(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;
capPath.AddLines(points, 3);
// Create a CustomLineCap object with capPath as the stroke path.
CustomLineCap custCap(NULL, &capPath);
// Set the width scale for custCap.
custCap.SetWidthScale(3);
// Assign custCap to a Pen object and draw a line.
Pen widthScalePen(Color(255, 0, 180, 180), 1.7f);
widthScalePen.SetCustomEndCap(&custCap);
graphics.DrawLine(&widthScalePen, Point(0, 0), Point(200, 200));
}
PowerBASIC
SUB GDIP_SetWidthScale (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pCapPath AS DWORD
LOCAL pCustCap AS DWORD
LOCAL pWidthScalePen 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, pCustCap)
' // // Set the width scale for custCap.
hStatus = GdipSetCustomLineCapWidthScale(pCustCap, 3)
' // Assign custCap to a Pen object and draw a line.
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 180, 180), 1.7!, %UnitWorld, pWidthScalePen)
hStatus = GdipSetPenCustomEndCap(pWidthScalePen, pCustCap)
hStatus = GdipDrawLineI(pGraphics, pWidthScalePen, 0, 0, 200, 200)
' // Cleanup
IF pWidthScalePen THEN GdipDeletePen(pWidthScalePen)
IF pCustCap THEN GdipDeleteCustomLineCap(pCustCap)
IF pCapPath THEN GdipDeletePath(pCapPath)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipSetCustomLineCapWidthScale.png)