Graphics.EnumerateMetafile(const Metafile*, const PointF, 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.

Syntax

Status EnumerateMetafile(
  [in]       const Metafile *metafile,
  [in, ref]  const PointF &destPoint,
  [in]       EnumerateMetafileProc callback,
  [in]       VOID *callbackData,
  [in]       ImageAttributes *imageAttributes
);

Parameters

metafile [in]

Type: const Metafile*

Pointer to a metafile to be enumerated.

destPoint [in, ref]

Type: const PointF

Reference to a point that specifies the upper-left corner of the displayed metafile.

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:

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.

Examples

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_EnumerateMetafile3(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);
   }
   // Enumerate pMeta, passing pMeta as the callback data. 
   graphics.EnumerateMetafile(pMeta, PointF(0.0f, 0.0f), metaCallback, pMeta);
   graphics.DrawImage(pMeta, Point(0, 150));
   delete pMeta;
}

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplusgraphics.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions

ADD
Show: