Graphics.EnumerateMetafile(const Metafile*, const Point*, INT, const RectF, Unit, EnumerateMetafileProc, VOID*, ImageAttributes*) method

Applies to: desktop apps only

The Graphics::EnumerateMetafile method calls an application-defined callback function for each record in a specified metafile. You can use this method to display a metafile by calling PlayRecord in the callback function.


Status EnumerateMetafile(
  [in]       const Metafile *metafile,
  [in]       const Point *destPoints,
  [in]       INT count,
  [in, ref]  const RectF &srcRect,
  [in]       Unit srcUnit,
  [in]       EnumerateMetafileProc callback,
  [in]       VOID *callbackData,
  [in]       ImageAttributes *imageAttributes


metafile [in]

Type: const Metafile*

Pointer to a metafile to be enumerated.

destPoints [in]

Type: const Point*

Pointer to an array of destination points. This is an array of three points that defines the destination parallelogram for the displayed metafile.

count [in]

Type: INT

Integer that specifies the number of points in the destPoints array.

srcRect [in, ref]

Type: const RectF

Reference to the rectangle that specifies the portion of the metafile that is displayed.

srcUnit [in]

Type: Unit

Element of the Unit enumeration that specifies the unit of measure for the source rectangle.

callback [in]

Type: EnumerateMetafileProc

Pointer to an application-defined callback function. The prototype for the callback function is given in Gdiplustypes.h.

callbackData [in]

Type: VOID*

Optional. Pointer to a block of data that is passed to the callback function. The default value is NULL.

imageAttributes [in]

Type: ImageAttributes*

Optional. Pointer to an ImageAttributes object that specifies color adjustments for the displayed metafile. The default value is NULL.

Return value


Type: Status

If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.


The following example creates a Metafile object and writes two records to the metafile. Then the code passes the address of that Metafile object to the Graphics::EnumerateMetafile method. The Graphics::EnumerateMetafile method calls the callback function (metaCallback) for each of the records in the metafile. The callback function plays only one of the two records in the metafile, namely the one that has a record type of EmfPlusRecordTypeFillEllipse.

Note that the argument passed to the callbackData parameter is the address of the Metafile object that is being enumerated. The callback function must have that pointer so that it can call the PlayRecord method of the Metafile object that is being enumerated.

BOOL CALLBACK metaCallback(
   EmfPlusRecordType recordType, 
   unsigned int flags, 
   unsigned int dataSize, 
   const unsigned char* pStr, 
   void* callbackData)
   // Play only EmfPlusRecordTypeFillEllipse records.
   if (recordType == EmfPlusRecordTypeFillEllipse)
   // Explicitly cast callbackData as a metafile pointer, and use it to call
   // the PlayRecord method.
   static_cast < Metafile* > (callbackData)->PlayRecord(recordType, flags, dataSize, pStr);
   return TRUE; 

VOID Example_EnumerateMetafile8(HDC hdc)
   Graphics graphics(hdc);
   // Create a Metafile object from an existing disk metafile.
   Metafile* pMeta = new Metafile(L"SampleMetafile.emf", hdc);
      // Fill a rectangle and an ellipse in pMeta.
      Graphics metaGraphics(pMeta);
      metaGraphics.FillRectangle(&SolidBrush(Color(255, 0, 0, 0)), 0, 0, 100, 100);
      metaGraphics.FillEllipse(&SolidBrush(Color(255, 255, 0, 0)), 100, 0, 200, 100);
   //Set up a destination rectangle.
   PointF points[] = {PointF(0.0f, 0.0f), PointF(300.0f, 0.0f), PointF(0.0f, 50.0f)};
   PointF* pPoints = points;
   // Enumerate a portion of pMeta, passing pMeta as the callback data. 
   RectF(0.0f, 0.0f, 300.0f, 50.0f),
   // Draw pMeta as an image.
   graphics.DrawImage(pMeta, Point(0, 150));
   delete pMeta;


Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server


GDI+ 1.0


Gdiplusgraphics.h (include Gdiplus.h)







Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions