• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipPathIterGetSubpathCount

Started by José Roca, June 22, 2008, 04:34:54 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a GraphicsPath object and adds three subpaths (figures) to the path. The code creates a graphics path iterator and calls its GdipPathIterGetSubpathCount function to determine the number of subpaths in the path. Then the code displays the count.

C++


#define BUFFER_SIZE 30
TCHAR numSubpaths[BUFFER_SIZE];

Point pts[] = {Point(20, 20),
               Point(40, 20),
               Point(40, 40)};

GraphicsPath     path;
path.AddLines(pts, 3);

path.StartFigure();
path.AddLine(20, 20, 100, 100);

path.StartFigure();
Rect rect(20, 20, 100, 50);
path.AddRectangle(rect);

// Create a GraphicsPathIterator object, and get the number of subpaths.
GraphicsPathIterator pathIterator(&path);
INT subpathCount = pathIterator.GetSubpathCount();

// Confirm that the subpaths were counted correctly.
StringCchPrintf(
   numSubpaths, BUFFER_SIZE, TEXT("There are %d subpaths."), subpathCount);

MessageBox(hWnd, numSubpaths, TEXT("SubpathCount"), NULL);


PowerBASIC


SUB GDIP_PathIterGetSubpathCount (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pIterator AS DWORD
   LOCAL count AS LONG
   DIM   pts(3) AS POINTF

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a path that has a rectangle and an ellipse.
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

   ' // Add some lines to a path.
   pts(0).x = 20 : pts(0).y = 20
   pts(1).x = 40 : pts(1).y = 20
   pts(2).x = 40 : pts(2).y = 40

   hStatus = GdipAddPathLine2(pPath, pts(0), 3)

   hStatus = GdipStartPathFigure(pPath)
   hStatus = GdipAddPathLine(pPath, 20, 20, 100, 100)

   hStatus = GdipStartPathFigure(pPath)
   hStatus = GdipAddPathRectangle(pPath, 20, 20, 100, 100)

   ' // Create a GraphicsPathIterator object, and get the number of subpaths.
   hStatus = GdipCreatePathIter(pIterator, pPath)
   hStatus = GdipPathIterGetSubpathCount(pIterator, count)

   ' // Confirm that the subpaths were counted correctly.
   MSGBOX "count =" & STR$(count)

   ' // Cleanup
   IF pIterator THEN GdipDeletePathIter(pIterator)
   IF pPath THEN GdipDeletePath(pPath)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB