The following example creates a
GraphicsPath object and adds five figures to the path. The calls to the
GdipSetPathMarker function place two markers in the path. The first marker is at the end of a figure, and the second marker is in the middle of a figure. The code passes the address of the
GraphicsPath object to the
GdipCreatePathIter function to create an iterator that is associated with the path. Then the code calls the
GdipPathIterNextMarker function twice to obtain the starting and ending indices of the second marker-delimited section of the path. Finally, the code draws the data points that belong to the second marker-delimited section of the path.
C++
VOID NextMarkerExample2(HDC hdc)
{
Graphics graphics(hdc);
// Create a graphics path with five figures (subpaths).
GraphicsPath path;
path.AddRectangle(Rect(20, 20, 60, 30));
path.SetMarker(); // first marker
path.AddLine(100, 20, 160, 50);
path.AddArc(180, 20, 60, 30, 0, 180);
path.AddRectangle(Rect(260, 20, 60, 30));
path.AddLine(340, 20, 400, 50);
path.SetMarker(); // second marker
path.AddArc(340, 20, 60, 30, 0, 180);
path.CloseFigure();
path.AddRectangle(Rect(420, 20, 60, 30));
// Create an iterator, and associate it with the path.
GraphicsPathIterator iterator(&path);
// Get the second marker-delimited section by calling NextMarker twice.
INT start;
INT end;
INT count;
count = iterator.NextMarker(&start, &end);
count = iterator.NextMarker(&start, &end);
// Get the data points of the second marker-delimited section.
PointF* points = new PointF[count];
BYTE* types = new BYTE[count];
iterator.CopyData(points, types, start, end);
// Draw the data points of the second marker-delimited section.
SolidBrush brush(Color(255, 255, 0, 0));
for(INT j = 0; j < count; ++j)
graphics.FillEllipse(
&brush,
points[j].X - 3.0f,
points[j].Y - 3.0f,
6.0f,
6.0f);
delete points;
delete types;
}
PowerBASIC
SUB GDIP_PathIterNextMarker (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPath AS DWORD
LOCAL pIterator AS DWORD
LOCAL pBrush AS DWORD
LOCAL count AS LONG
LOCAL resultCount AS LONG
LOCAL startIndex AS LONG
LOCAL endIndex AS LONG
LOCAL i AS LONG
DIM pPoints(0) AS POINTF
DIM pTypes(0) AS BYTE
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create a graphics path with five figures (subpaths).
hStatus = GdipCreatePath(%FillModeAlternate, pPath)
hStatus = GdipAddPathRectangle(pPath, 20, 20, 60, 30)
hStatus = GdipSetPathMarker(pPath) ' // first marker
hStatus = GdipAddPathLine(pPath, 100, 20, 160, 50)
hStatus = GdipAddPathArc(pPath, 180, 20, 60, 30, 0, 180)
hStatus = GdipAddPathRectangle(pPath, 260, 20, 60, 30)
hStatus = GdipAddPathLine(pPath, 340, 20, 400, 50)
hStatus = GdipSetPathMarker(pPath) ' // second marker
hStatus = GdipAddPathArc(pPath, 340, 20, 60, 30, 0, 180)
hStatus = GdipClosePathFigure(pPath)
hStatus = GdipAddPathRectangle(pPath, 420, 20, 60, 30)
' // Create an iterator, and associate it with the path.
hStatus = GdipCreatePathIter(pIterator, pPath)
' // Get the second marker-delimited section by calling NextMarker twice.
hStatus = GdipPathIterNextMarker(pIterator, count, startIndex, endIndex)
hStatus = GdipPathIterNextMarker(pIterator, count, startIndex, endIndex)
' // Get the data points of the second marker-delimited section.
IF count THEN
REDIM pPoints(count - 1)
REDIM pTypes(count - 1)
hStatus = GdipPathIterCopyData(pIterator, resultCount, pPoints(0), pTypes(0), startIndex, endIndex)
' // Draw the data points of the second marker-delimited section.
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pBrush)
FOR i = 0 TO count - 1
hStatus = GdipFillEllipse(pGraphics, pBrush, pPoints(i).x - 3, pPoints(i).y - 3, 6, 6)
NEXT
END IF
' // Cleanup
IF pBrush THEN GdipDeleteBrush(pBrush)
IF pIterator THEN GdipDeletePathIter(pIterator)
IF pPath THEN GdipDeletePath(pPath)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipPathIterNextMarker.png)