The following example creates a
GraphicsPath object and adds a closed curve to the path. The code creates a green pen that has a width of 10, changes its style to
DashStyleDash, and passes the address of that pen to the
GdipWidenPath function. Then the code draws the path with a blue pen of width 1.
C++
VOID WidenExample(HDC hdc)
{
Graphics graphics(hdc);
Pen bluePen(Color(255, 0, 0, 255));
Pen greenPen(Color(255, 0, 255, 0), 10);
PointF points[] = {
PointF(20.0f, 20.0f),
PointF(160.0f, 100.0f),
PointF(140.0f, 60.0f),
PointF(60.0f, 100.0f)};
GraphicsPath path;
path.AddClosedCurve(points, 4);
path.Widen(&greenPen);
graphics.DrawPath(&bluePen, &path);
}
PowerBASIC
SUB GDIP_WidenPath (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPath AS DWORD
LOCAL pBluePen AS DWORD
LOCAL pGreenPen AS DWORD
DIM pts(3) AS POINTF
' // Create the Graphics object.
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create the pens.
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 255), 1, %UnitWorld, pBluePen)
hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 255, 0), 10, %UnitWorld, pGreenPen)
' // Create the Path object.
hStatus = GdipCreatePath(%FillModeAlternate, pPath)
' // Add a closed curve.
pts(0).x = 20 : pts(0).y = 20
pts(1).x = 160 : pts(1).y = 100
pts(2).x = 140 : pts(2).y = 60
pts(3).x = 60 : pts(3).y = 100
hStatus = GdipAddPathClosedCurve(pPath, pts(0), 4)
' // The GdipWidenPath function respects the dash style of the specified pen
' // (the green pen in this case). The following instruction changes it.
hStatus = GdipSetPenDashStyle(pGreenPen, %DashStyleDash)
' // Widen tha path.
hStatus = GdipWidenPath(pPath, pGreenPen, %NULL, FlatnessDefault)
' // Draw the path.
hStatus = GdipDrawPath(pGraphics, pBluePen, pPath)
' // Cleanup
IF pBluePen THEN GdipDeletePen(pBluePen)
IF pGreenPen THEN GdipDeletePen(pGreenPen)
IF pPath THEN GdipDeletePath(pPath)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipWidenPath.png)