using System; using System.Runtime.InteropServices; using System.Text; using Vanara.Extensions; using Vanara.InteropServices; namespace Vanara.PInvoke { public static partial class Gdi32 { /// /// The EnhMetaFileProc function is an application-defined callback function used with the EnumEnhMetaFile function. The /// ENHMFENUMPROC type defines a pointer to this callback function. EnhMetaFileProc is a placeholder for the /// application-defined function name. /// /// Handle to the device context passed to EnumEnhMetaFile. /// /// Pointer to a HANDLETABLE structure representing the table of handles associated with the graphics objects (pens, brushes, and so /// on) in the metafile. The first entry contains the enhanced-metafile handle. /// /// /// Pointer to one of the records in the metafile. This record should not be modified. (If modification is necessary, it should be /// performed on a copy of the record.) /// /// Specifies the number of objects with associated handles in the handle table. /// Pointer to optional data. /// This function must return a nonzero value to continue enumeration; to stop enumeration, it must return zero. /// An application must register the callback function by passing its address to the EnumEnhMetaFile function. // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nc-wingdi-enhmfenumproc ENHMFENUMPROC Enhmfenumproc; int Enhmfenumproc( // HDC hdc, HANDLETABLE *lpht, const ENHMETARECORD *lpmr, int nHandles, LPARAM data ) {...} [PInvokeData("wingdi.h", MSDNShortId = "c9f04b38-18bc-4b52-8c56-d9475bc30202")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate int EnhMetaFileProc(HDC hdc, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] HGDIOBJ[] lpht, [In] IntPtr lpmr, int nHandles, IntPtr data); /// /// /// The EnumMetaFileProc function is an application-defined callback function that processes Windows-format metafile records. /// This function is called by the EnumMetaFile function. The MFENUMPROC type defines a pointer to this callback function. /// EnumMetaFileProc is a placeholder for the application-defined function name. /// /// /// Note This function is provided only for compatibility with Windows-format metafiles. Enhanced-format metafiles provide /// superior functionality and are recommended for new applications. The corresponding function for an enhanced-format metafile is EnhMetaFileProc. /// /// /// /// An application must register the callback function by passing its address to the EnumMetaFile function. /// EnumMetaFileProc is a placeholder for the application-supplied function name. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nc-wingdi-mfenumproc MFENUMPROC Mfenumproc; int Mfenumproc( HDC hdc, // HANDLETABLE *lpht, METARECORD *lpMR, int nObj, LPARAM param ) {...} [PInvokeData("wingdi.h", MSDNShortId = "ebef5a3f-0dd7-49df-a07d-c55c5e8c868c")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate int EnumMetaFileProc(HDC hdc, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] HGDIOBJ[] lpht, [In] IntPtr lpMR, int nObj, IntPtr param); /// /// The RecordType enumeration defines values that uniquely identify records in an EMF metafile. These values are specified in the /// Type fields of EMF records (section 2.3). /// [PInvokeData("wingdi.h")] public enum RecordType : uint { /// /// This record defines the start of the metafile and specifies its characteristics; its contents, including the dimensions of /// the embedded image; the number of records in the metafile; and the resolution of the device on which the embedded image was /// created. These values make it possible for the metafile to be device-independent. /// EMR_HEADER = 1, /// /// This record defines one or more Bezier curves. Cubic Bezier curves are defined using specified endpoints and control points, /// and are stroked with the current pen. /// EMR_POLYBEZIER = 2, /// /// This record defines a polygon consisting of two or more vertexes connected by straight lines. The polygon is outlined by /// using the current pen and filled by using the current brush and polygon fill mode. The polygon is closed automatically by /// drawing a line from the last vertex to the first. /// EMR_POLYGON = 3, /// This record defines a series of line segments by connecting the points in the specified array. EMR_POLYLINE = 4, /// This record defines one or more Bezier curves based upon the current drawing position. EMR_POLYBEZIERTO = 5, /// /// This record defines one or more straight lines based upon the current drawing position. A line is drawn from the current /// drawing position to the first point specified by the points field by using the current pen. For each additional line, drawing /// is performed from the ending point of the previous line to the next point specified by points. /// EMR_POLYLINETO = 6, /// /// This record defines multiple series of connected line segments. The line segments are drawn by using the current pen. The /// figures formed by the segments are not filled. The current position is neither used nor updated by this record. /// EMR_POLYPOLYLINE = 7, /// /// This record defines a series of closed polygons. Each polygon is outlined by using the current pen and filled by using the /// current brush and polygon fill mode. The polygons defined by this record can overlap. /// EMR_POLYPOLYGON = 8, /// This record defines the window extent. EMR_SETWINDOWEXTEX = 9, /// This record defines the window origin. EMR_SETWINDOWORGEX = 10, /// This record defines the viewport extent. EMR_SETVIEWPORTEXTEX = 11, /// This record defines the viewport origin. EMR_SETVIEWPORTORGEX = 12, /// This record defines the origin of the current brush. EMR_SETBRUSHORGEX = 13, /// This record indicates the end of the metafile. EMR_EOF = 14, /// This record defines the color of the pixel at the specified logical coordinates. EMR_SETPIXELV = 15, /// /// This record specifies parameters for the process of matching logical fonts to physical fonts, which is performed by the font mapper. /// EMR_SETMAPPERFLAGS = 16, /// /// This record defines the mapping mode, which defines the unit of measure used to transform page space units into device space /// units, and defines the orientation of the device's X and Y axes. /// EMR_SETMAPMODE = 17, /// /// This record defines the background mix mode, which is used with text, hatched brushes, and pen styles that are not solid lines. /// EMR_SETBKMODE = 18, /// This record defines polygon fill mode. EMR_SETPOLYFILLMODE = 19, /// This record defines binary raster operation mode. EMR_SETROP2 = 20, /// This record defines bitmap stretch mode. EMR_SETSTRETCHBLTMODE = 21, /// This record defines text alignment. EMR_SETTEXTALIGN = 22, /// This record defines the color adjustment values using the specified values. EMR_SETCOLORADJUSTMENT = 23, /// This record defines the current text color. EMR_SETTEXTCOLOR = 24, /// This record defines the background color. EMR_SETBKCOLOR = 25, /// This record redefines the current clipping region by the specified offsets. EMR_OFFSETCLIPRGN = 26, /// This record defines coordinates of the new drawing position in logical units. EMR_MOVETOEX = 27, /// /// This record intersects the current clipping region with the current metaregion and saves the combined region as the new /// current metaregion. /// EMR_SETMETARGN = 28, /// /// This record defines a new clipping region that consists of the current clipping region intersected with the specified rectangle. /// EMR_EXCLUDECLIPRECT = 29, /// /// This record defines a new clipping region from the intersection of the current clipping region and the specified rectangle. /// EMR_INTERSECTCLIPRECT = 30, /// This record redefines the viewport using the ratios formed by the specified multiplicands and divisors. EMR_SCALEVIEWPORTEXTEX = 31, /// This record redefines the window using the ratios formed by the specified multiplicands and divisors. EMR_SCALEWINDOWEXTEX = 32, /// /// This record saves the current state of the playback device context (section 3.1) in an array of states saved by preceding /// EMR_SAVEDC records if any. /// EMR_SAVEDC = 33, /// /// This record restores the playback device context to the specified state, which was saved by a preceding EMR_SAVEDC record /// (section 2.3.11). /// EMR_RESTOREDC = 34, /// This record defines a two-dimensional linear transform between world space and page space [MSDN-WRLDPGSPC]. EMR_SETWORLDTRANSFORM = 35, /// This record redefines the world transform by using the specified mode. EMR_MODIFYWORLDTRANSFORM = 36, /// /// This record selects an object in the playback device context, which is identified by its index in the EMF object table /// (section 3.1.1.1). /// EMR_SELECTOBJECT = 37, /// This record defines a logical pen (section 2.2.19) that has the specified style, width, and color. EMR_CREATEPEN = 38, /// This record defines a logical brush for filling figures in graphics operations. EMR_CREATEBRUSHINDIRECT = 39, /// This record deletes a graphics object, clearing its index in the EMF object table. EMR_DELETEOBJECT = 40, /// /// This record defines a line segment of an arc. The line segment is drawn from the current drawing position to the beginning of /// the arc. The arc is drawn along the perimeter of a circle with the given radius and center. The length of the arc is defined /// by the given start and sweep angles. /// EMR_ANGLEARC = 41, /// /// This record defines an ellipse. The center of the ellipse is the center of the specified bounding rectangle. The ellipse is /// outlined by using the current pen and is filled by using the current brush. /// EMR_ELLIPSE = 42, /// /// This record defines a rectangle. The rectangle is outlined by using the current pen and filled by using the current brush. /// EMR_RECTANGLE = 43, /// /// This record defines a rectangle with rounded corners. The rectangle is outlined by using the current pen and filled by using /// the current brush. /// EMR_ROUNDRECT = 44, /// This record defines an elliptical arc. EMR_ARC = 45, /// /// This record defines a chord, which is a region bounded by the intersection of an ellipse and a line segment, called a secant. /// The chord is outlined by using the current pen and filled by using the current brush. /// EMR_CHORD = 46, /// /// This record defines a pie-shaped wedge bounded by the intersection of an ellipse and two radials. The pie is outlined by /// using the current pen and filled by using the current brush. /// EMR_PIE = 47, /// /// This record selects a LogPalette object (section 2.2.17) into the playback device context, identifying it by its index in the /// EMF object table. /// EMR_SELECTPALETTE = 48, /// This record defines a LogPalette object. EMR_CREATEPALETTE = 49, /// This record defines RGB color values in a range of entries in a LogPalette object. EMR_SETPALETTEENTRIES = 50, /// This record increases or decreases the size of a logical palette. EMR_RESIZEPALETTE = 51, /// This record maps entries from the current logical palette to the system palette. EMR_REALIZEPALETTE = 52, /// This record fills an area of the display surface with the current brush. EMR_EXTFLOODFILL = 53, /// /// This record defines a line from the current drawing position up to, but not including, the specified point. It resets the /// current drawing position to the specified point. /// EMR_LINETO = 54, /// This record defines an elliptical arc. It resets the current position to the endpoint of the arc. EMR_ARCTO = 55, /// This record defines a set of line segments and Bezier curves. EMR_POLYDRAW = 56, /// This record defines the drawing direction to be used for arc and rectangle operations. EMR_SETARCDIRECTION = 57, /// This record defines the limit for the length of miter joins. EMR_SETMITERLIMIT = 58, /// This record opens a path bracket for specifying the current path. EMR_BEGINPATH = 59, /// This record closes an open path bracket and selects the path into the playback device context. EMR_ENDPATH = 60, /// This record closes an open figure in a path. EMR_CLOSEFIGURE = 61, /// /// This record closes any open figures in the current path bracket and fills its interior by using the current brush and /// polygon-filling mode. /// EMR_FILLPATH = 62, /// /// This record closes any open figures in a path, strokes the outline of the path by using the current pen, and fills its /// interior by using the current brush. /// EMR_STROKEANDFILLPATH = 63, /// This record renders the specified path by using the current pen. EMR_STROKEPATH = 64, /// This record turns each curve in the path into a sequence of lines. EMR_FLATTENPATH = 65, /// /// This record redefines the current path bracket as the area that would be painted if the path were stroked using the current pen. /// EMR_WIDENPATH = 66, /// /// This record specifies a clipping region as the current clipping region combined with the current path bracket, using the /// specified mode. /// EMR_SELECTCLIPPATH = 67, /// This record aborts a path bracket or discards the path from a closed path bracket. EMR_ABORTPATH = 68, /// This record specifies arbitrary private data. EMR_GDICOMMENT = 70, /// This record fills the specified region by using the specified brush. EMR_FILLRGN = 71, /// This record draws a border around the specified region using the specified brush. EMR_FRAMERGN = 72, /// This record inverts the colors in the specified region. EMR_INVERTRGN = 73, /// This record paints the specified region by using the current brush. EMR_PAINTRGN = 74, /// This record combines the specified region with the current clipping region, using the specified mode. EMR_EXTSELECTCLIPRGN = 75, /// /// This record specifies a block transfer of pixels from a source bitmap to a destination rectangle, optionally in combination /// with a brush pattern, according to a specified raster operation. /// EMR_BITBLT = 76, /// /// This record specifies a block transfer of pixels from a source bitmap to a destination rectangle, optionally in combination /// with a brush pattern, according to a specified raster operation, stretching or compressing the output to fit the dimensions /// of the destination, if necessary. /// EMR_STRETCHBLT = 77, /// /// This record specifies a block transfer of pixels from a source bitmap to a destination rectangle, optionally in combination /// with a brush pattern and with the application of a color mask bitmap, according to specified foreground and background raster operations. /// EMR_MASKBLT = 78, /// /// This record specifies a block transfer of pixels from a source bitmap to a destination parallelogram, with the application of /// a color mask bitmap. /// EMR_PLGBLT = 79, /// /// This record specifies a block transfer of pixels from specified scanlines of a source bitmap to a destination rectangle. /// EMR_SETDIBITSTODEVICE = 80, /// /// This record specifies a block transfer of pixels from a source bitmap to a destination rectangle, optionally in combination /// with a brush pattern, according to a specified raster operation, stretching or compressing the output to fit the dimensions /// of the destination, if necessary. /// EMR_STRETCHDIBITS = 81, /// /// This record defines a logical font that has the specified characteristics. The font can subsequently be selected as the /// current font. /// EMR_EXTCREATEFONTINDIRECTW = 82, /// This record draws an ASCII text string using the current font and text colors. EMR_EXTTEXTOUTA = 83, /// This record draws a Unicode text string using the current font and text colors. EMR_EXTTEXTOUTW = 84, /// This record defines one or more Bezier curves. The curves are drawn using the current pen. EMR_POLYBEZIER16 = 85, /// /// This record defines a polygon consisting of two or more vertexes connected by straight lines. The polygon is outlined by /// using the current pen and filled by using the current brush and polygon fill mode. The polygon is closed automatically by /// drawing a line from the last vertex to the first. /// EMR_POLYGON16 = 86, /// This record defines a series of line segments by connecting the points in the specified array. EMR_POLYLINE16 = 87, /// This record defines one or more Bezier curves based on the current position. EMR_POLYBEZIERTO16 = 88, /// /// This record defines one or more straight lines based upon the current position. A line is drawn from the current position to /// the first point specified by the Points field by using the current pen. For each additional line, drawing is performed from /// the ending point of the previous line to the next point specified by Points. /// EMR_POLYLINETO16 = 89, /// This record defines multiple series of connected line segments. EMR_POLYPOLYLINE16 = 90, /// /// This record defines a series of closed polygons. Each polygon is outlined by using the current pen and filled by using the /// current brush and polygon fill mode. The polygons specified by this record can overlap. /// EMR_POLYPOLYGON16 = 91, /// This record defines a set of line segments and Bezier curves. EMR_POLYDRAW16 = 92, /// /// This record defines a logical brush with the specified bitmap pattern. The bitmap can be a device-independent bitmap (DIB) /// section bitmap or it can be a device-dependent bitmap. /// EMR_CREATEMONOBRUSH = 93, /// This record defines a logical brush that has the pattern specified by the DIB. EMR_CREATEDIBPATTERNBRUSHPT = 94, /// /// This record defines an extended logical pen (section 2.2.20) that has the specified style, width, color, and brush attributes. /// EMR_EXTCREATEPEN = 95, /// /// This record draws one or more ASCII text strings using the current font and text colors. Note: EMR_POLYTEXTOUTA SHOULD be /// emulated with a series of EMR_EXTTEXTOUTW records, one per string. /// EMR_POLYTEXTOUTA = 96, /// /// This record draws one or more Unicode text strings using the current font and text colors. Note: EMR_POLYTEXTOUTW SHOULD be /// emulated with a series of EMR_EXTTEXTOUTW records, one per string. /// EMR_POLYTEXTOUTW = 97, /// This record specifies the mode of Image Color Management (ICM) for graphics operations. EMR_SETICMMODE = 98, /// This record creates a logical color space object from a color profile with a name consisting of ASCII characters. EMR_CREATECOLORSPACE = 99, /// This record defines the current logical color space object for graphics operations. EMR_SETCOLORSPACE = 100, /// /// This record deletes a logical color space object. Note: An EMR_DELETEOBJECT record SHOULD be used instead of /// EMR_DELETECOLORSPACE to delete a logical color space object. /// EMR_DELETECOLORSPACE = 101, /// This record specifies an OpenGL function. EMR_GLSRECORD = 102, /// This record specifies an OpenGL function with a bounding rectangle for output. EMR_GLSBOUNDEDRECORD = 103, /// This record specifies the pixel format to use for graphics operations. EMR_PIXELFORMAT = 104, /// /// This record passes arbitrary information to the driver. The intent is that the information results in drawing being done. /// EMR_DRAWESCAPE = 105, /// /// This record passes arbitrary information to the driver. The intent is that the information does not result in drawing being done. /// EMR_EXTESCAPE = 106, /// This record outputs a string. EMR_SMALLTEXTOUT = 108, /// /// This record forces the font mapper to match fonts based on their UniversalFontId in preference to their LogFont information. /// EMR_FORCEUFIMAPPING = 109, /// This record passes arbitrary information to the given named driver. EMR_NAMEDESCAPE = 110, /// /// This record specifies how to correct the entries of a logical palette object using Windows Color System (WCS) 1.0 values. /// EMR_COLORCORRECTPALETTE = 111, /// This record specifies a color profile in a file with a name consisting of ASCII characters, for graphics output. EMR_SETICMPROFILEA = 112, /// This record specifies a color profile in a file with a name consisting of Unicode characters, for graphics output. EMR_SETICMPROFILEW = 113, /// /// This record specifies a block transfer of pixels from a source bitmap to a destination rectangle, including alpha /// transparency data, according to a specified blending operation. /// EMR_ALPHABLEND = 114, /// This record specifies the order in which text and graphics are drawn. EMR_SETLAYOUT = 115, /// /// This record specifies a block transfer of pixels from a source bitmap to a destination rectangle, treating a specified color /// as transparent, stretching or compressing the output to fit the dimensions of the destination, if necessary. /// EMR_TRANSPARENTBLT = 116, /// This record specifies filling rectangles or triangles with gradients of color. EMR_GRADIENTFILL = 118, /// This record sets the UniversalFontIds (section 2.2.27) of linked fonts to use during character lookup. EMR_SETLINKEDUFIS = 119, /// This record specifies the amount of extra space to add to break characters for justification purposes. EMR_SETTEXTJUSTIFICATION = 120, /// /// This record specifies whether to perform color matching with a color profile that is specified in a file with a name /// consisting of Unicode characters. /// EMR_COLORMATCHTOTARGETW = 121, /// This record creates a logical color space object from a color profile with a name consisting of Unicode characters. EMR_CREATECOLORSPACEW = 122, } /// /// The CloseEnhMetaFile function closes an enhanced-metafile device context and returns a handle that identifies an /// enhanced-format metafile. /// /// Handle to an enhanced-metafile device context. /// /// If the function succeeds, the return value is a handle to an enhanced metafile. /// If the function fails, the return value is NULL. /// /// /// /// An application can use the enhanced-metafile handle returned by the CloseEnhMetaFile function to perform the following tasks: /// /// /// /// Display a picture stored in an enhanced metafile /// /// /// Create copies of the enhanced metafile /// /// /// Enumerate, edit, or copy individual records in the enhanced metafile /// /// /// Retrieve an optional description of the metafile contents from the enhanced-metafile header /// /// /// Retrieve a copy of the enhanced-metafile header /// /// /// Retrieve a binary copy of the enhanced metafile /// /// /// Enumerate the colors in the optional palette /// /// /// Convert an enhanced-format metafile into a Windows-format metafile /// /// /// /// When the application no longer needs the enhanced metafile handle, it should release the handle by calling the DeleteEnhMetaFile function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-closeenhmetafile HENHMETAFILE CloseEnhMetaFile( HDC hdc ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "3c4a0d8b-75a5-4729-8c64-476c36d01a90")] public static extern SafeHENHMETAFILE CloseEnhMetaFile(HDC hdc); /// /// /// The CloseMetaFile function closes a metafile device context and returns a handle that identifies a Windows-format metafile. /// /// /// Note This function is provided only for compatibility with Windows-format metafiles. Enhanced-format metafiles provide /// superior functionality and are recommended for new applications. The corresponding function for an enhanced-format metafile is CloseEnhMetaFile. /// /// /// Handle to a metafile device context used to create a Windows-format metafile. /// /// If the function succeeds, the return value is a handle to a Windows-format metafile. /// If the function fails, the return value is NULL. /// /// /// To convert a Windows-format metafile into a new enhanced-format metafile, use the SetWinMetaFileBits function. /// /// When an application no longer needs the Windows-format metafile handle, it should delete the handle by calling the DeleteMetaFile function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-closemetafile HMETAFILE CloseMetaFile( HDC hdc ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "8e50457a-8ef8-4e71-8c56-38cfb277f57d")] public static extern HMETAFILE CloseMetaFile(HDC hdc); /// The CopyEnhMetaFile function copies the contents of an enhanced-format metafile to a specified file. /// A handle to the enhanced metafile to be copied. /// /// A pointer to the name of the destination file. If this parameter is NULL, the source metafile is copied to memory. /// /// /// If the function succeeds, the return value is a handle to the copy of the enhanced metafile. /// If the function fails, the return value is NULL. /// /// /// /// Where text arguments must use Unicode characters, use the CopyEnhMetaFile function as a wide-character function. Where /// text arguments must use characters from the Windows character set, use this function as an ANSI function. /// /// Applications can use metafiles stored in memory for temporary operations. /// /// When the application no longer needs the enhanced-metafile handle, it should delete the handle by calling the DeleteEnhMetaFile function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-copyenhmetafilea HENHMETAFILE CopyEnhMetaFileA( HENHMETAFILE // hEnh, LPCSTR lpFileName ); [DllImport(Lib.Gdi32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wingdi.h", MSDNShortId = "7c428828-b239-41d4-926c-88caa0aa7214")] public static extern SafeHENHMETAFILE CopyEnhMetaFile(HENHMETAFILE hEnh, [Optional] string lpFileName); /// /// The CopyMetaFile function copies the content of a Windows-format metafile to the specified file. /// /// Note This function is provided only for compatibility with Windows-format metafiles. Enhanced-format metafiles provide /// superior functionality and are recommended for new applications. The corresponding function for an enhanced-format metafile is CopyEnhMetaFile. /// /// /// A handle to the source Windows-format metafile. /// /// A pointer to the name of the destination file. If this parameter is NULL, the source metafile is copied to memory. /// /// /// If the function succeeds, the return value is a handle to the copy of the Windows-format metafile. /// If the function fails, the return value is NULL. /// /// /// /// Where text arguments must use Unicode characters, use this function as a wide-character function. Where text arguments must use /// characters from the Windows character set, use this function as an ANSI function. /// /// /// When the application no longer needs the Windows-format metafile handle, it should delete the handle by calling the /// DeleteMetaFile function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-copymetafilea HMETAFILE CopyMetaFileA( HMETAFILE , LPCSTR ); [DllImport(Lib.Gdi32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wingdi.h", MSDNShortId = "e9f97591-697b-47d0-a748-60fda4d5258c")] public static extern SafeHMETAFILE CopyMetaFile(HMETAFILE arg1, string arg2); /// /// /// The CreateEnhMetaFile function creates a device context for an enhanced-format metafile. This device context can be used /// to store a device-independent picture. /// /// /// /// /// A handle to a reference device for the enhanced metafile. This parameter can be NULL; for more information, see Remarks. /// /// /// /// /// A pointer to the file name for the enhanced metafile to be created. If this parameter is NULL, the enhanced metafile is /// memory based and its contents are lost when it is deleted by using the DeleteEnhMetaFile function. /// /// /// /// /// A pointer to a RECT structure that specifies the dimensions (in .01-millimeter units) of the picture to be stored in the enhanced metafile. /// /// /// /// /// A pointer to a string that specifies the name of the application that created the picture, as well as the picture's title. This /// parameter can be NULL; for more information, see Remarks. /// /// /// /// If the function succeeds, the return value is a handle to the device context for the enhanced metafile. /// If the function fails, the return value is NULL. /// /// /// /// Where text arguments must use Unicode characters, use the CreateEnhMetaFile function as a wide-character function. Where /// text arguments must use characters from the Windows character set, use this function as an ANSI function. /// /// /// The system uses the reference device identified by the hdcRef parameter to record the resolution and units of the device on which /// a picture originally appeared. If the hdcRef parameter is NULL, it uses the current display device for reference. /// /// /// The left and top members of the RECT structure pointed to by the parameter must be less /// than the right and bottom members, respectively. Points along the edges of the rectangle are included in the /// picture. If is NULL, the graphics device interface (GDI) computes the dimensions of the smallest /// rectangle that surrounds the picture drawn by the application. The parameter should be provided where possible. /// /// /// The string pointed to by the lpDescription parameter must contain a null character between the application name and the picture /// name and must terminate with two null characters for example, "XYZ Graphics Editor\0Bald Eagle\0\0", where \0 represents the null /// character. If lpDescription is NULL, there is no corresponding entry in the enhanced-metafile header. /// /// /// Applications use the device context created by this function to store a graphics picture in an enhanced metafile. The handle /// identifying this device context can be passed to any GDI function. /// /// /// After an application stores a picture in an enhanced metafile, it can display the picture on any output device by calling the /// PlayEnhMetaFile function. When displaying the picture, the system uses the rectangle pointed to by the /// parameter and the resolution data from the reference device to position and scale the picture. /// /// The device context returned by this function contains the same default attributes associated with any new device context. /// Applications must use the GetWinMetaFileBits function to convert an enhanced metafile to the older Windows metafile format. /// The file name for the enhanced metafile should use the .emf extension. /// Examples /// For an example, see Creating an Enhanced Metafile. /// // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createenhmetafilea HDC CreateEnhMetaFileA( HDC hdc, LPCSTR // lpFilename, const RECT *lprc, LPCSTR lpDesc ); [DllImport(Lib.Gdi32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wingdi.h", MSDNShortId = "647f83ca-dca3-44af-a594-5f9ba2bd7607")] public static extern SafeHDC CreateEnhMetaFile([Optional] HDC hdc, [Optional] string lpFilename, [In, Optional] PRECT lprc, [Optional] string lpDesc); /// /// The CreateMetaFile function creates a device context for a Windows-format metafile. /// /// Note This function is provided only for compatibility with Windows-format metafiles. Enhanced-format metafiles provide /// superior functionality and are recommended for new applications. The corresponding function for an enhanced-format metafile is CreateEnhMetaFile. /// /// /// /// A pointer to the file name for the Windows-format metafile to be created. If this parameter is NULL, the Windows-format /// metafile is memory based and its contents are lost when it is deleted by using the DeleteMetaFile function. /// /// /// If the function succeeds, the return value is a handle to the device context for the Windows-format metafile. /// If the function fails, the return value is NULL. /// /// /// /// Where text arguments must use Unicode characters, use the CreateMetaFile function as a wide-character function. Where text /// arguments must use characters from the Windows character set, use this function as an ANSI function. /// /// /// CreateMetaFile is a Windows-format metafile function. This function supports only 16-bit Windows-based applications, which /// are listed in Windows-Format Metafiles. It does not record or play back GDI functions such as PolyBezier, which were not part of /// 16-bit Windows. /// /// /// The device context created by this function can be used to record GDI output functions in a Windows-format metafile. It cannot be /// used with GDI query functions such as GetTextColor. When the device context is used with a GDI output function, the return value /// of that function becomes TRUE if the function is recorded and FALSE otherwise. When an object is selected by using /// the SelectObject function, only a copy of the object is recorded. The object still belongs to the application. /// /// /// To create a scalable Windows-format metafile, record the graphics output in the MM_ANISOTROPIC mapping mode. The file cannot /// contain functions that modify the viewport origin and extents, nor can it contain device-dependent functions such as the /// SelectClipRgn function. Once created, the Windows metafile can be scaled and rendered to any output device-format by defining the /// viewport origin and extents of the picture before playing it. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createmetafilea HDC CreateMetaFileA( LPCSTR pszFile ); [DllImport(Lib.Gdi32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wingdi.h", MSDNShortId = "81b3baae-f0e6-4b71-a6de-953ad3376dbd")] public static extern HDC CreateMetaFile(string pszFile); /// /// The DeleteEnhMetaFile function deletes an enhanced-format metafile or an enhanced-format metafile handle. /// /// /// A handle to an enhanced metafile. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// /// If the hemf parameter identifies an enhanced metafile stored in memory, the DeleteEnhMetaFile function deletes the /// metafile. If hemf identifies a metafile stored on a disk, the function deletes the metafile handle but does not destroy the /// actual metafile. An application can retrieve the file by calling the GetEnhMetaFile function. /// /// Examples /// For an example, see Opening an Enhanced Metafile and Displaying Its Contents. /// // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-deleteenhmetafile BOOL DeleteEnhMetaFile( HENHMETAFILE hmf ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "d3b93b3b-fa0b-4480-8348-19919c9e904d")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DeleteEnhMetaFile(HENHMETAFILE hmf); /// /// The DeleteMetaFile function deletes a Windows-format metafile or Windows-format metafile handle. /// /// Note This function is provided only for compatibility with Windows-format metafiles. Enhanced-format metafiles provide /// superior functionality and are recommended for new applications. The corresponding function for an enhanced-format metafile is DeleteEnhMetaFile. /// /// /// A handle to a Windows-format metafile. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// If the metafile identified by the hmf parameter is stored in memory (rather than on a disk), its content is lost when it is /// deleted by using the DeleteMetaFile function. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deletemetafile BOOL DeleteMetaFile( HMETAFILE hmf ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "51766282-f185-4e29-a36e-1069d9d61f7c")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DeleteMetaFile(HMETAFILE hmf); /// /// The EnumEnhMetaFile function enumerates the records within an enhanced-format metafile by retrieving each record and /// passing it to the specified callback function. The application-supplied callback function processes each record as required. The /// enumeration continues until the last record is processed or when the callback function returns zero. /// /// A handle to a device context. This handle is passed to the callback function. /// A handle to an enhanced metafile. /// A pointer to the application-supplied callback function. For more information, see the EnhMetaFileProc function. /// A pointer to optional callback-function data. /// /// A pointer to a RECT structure that specifies the coordinates, in logical units, of the picture's upper-left and lower-right corners. /// /// /// If the callback function successfully enumerates all the records in the enhanced metafile, the return value is nonzero. /// /// If the callback function does not successfully enumerate all the records in the enhanced metafile, the return value is zero. /// /// /// /// /// Points along the edge of the rectangle pointed to by the lpRect parameter are included in the picture. If the hdc parameter is /// NULL, the system ignores lpRect. /// /// /// If the callback function calls the PlayEnhMetaFileRecord function, hdc must identify a valid device context. The system uses the /// device context's transformation and mapping mode to transform the picture displayed by the PlayEnhMetaFileRecord function. /// /// You can use the EnumEnhMetaFile function to embed one enhanced-metafile within another. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-enumenhmetafile BOOL EnumEnhMetaFile( HDC hdc, HENHMETAFILE // hmf, ENHMFENUMPROC proc, LPVOID param, const RECT *lpRect ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "bef5f43e-219a-4f8a-986d-290e29e17c4e")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool EnumEnhMetaFile([Optional] HDC hdc, HENHMETAFILE hmf, EnhMetaFileProc proc, [Optional] IntPtr param, [In, Optional] PRECT lpRect); /// /// /// The EnumMetaFile function enumerates the records within a Windows-format metafile by retrieving each record and passing it /// to the specified callback function. The application-supplied callback function processes each record as required. The enumeration /// continues until the last record is processed or when the callback function returns zero. /// /// /// Note This function is provided only for compatibility with Windows-format metafiles. Enhanced-format metafiles provide /// superior functionality and are recommended for new applications. The corresponding function for an enhanced-format metafile is EnumEnhMetaFile. /// /// /// Handle to a device context. This handle is passed to the callback function. /// Handle to a Windows-format metafile. /// Pointer to an application-supplied callback function. For more information, see EnumMetaFileProc. /// Pointer to optional data. /// /// If the callback function successfully enumerates all the records in the Windows-format metafile, the return value is nonzero. /// /// If the callback function does not successfully enumerate all the records in the Windows-format metafile, the return value is zero. /// /// /// /// To convert a Windows-format metafile into an enhanced-format metafile, use the SetWinMetaFileBits function. /// You can use the EnumMetaFile function to embed one Windows-format metafile within another. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-enummetafile BOOL EnumMetaFile( HDC hdc, HMETAFILE hmf, // MFENUMPROC proc, LPARAM param ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "b11c7467-64a9-442b-8dee-26e15f64a26b")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool EnumMetaFile([Optional] HDC hdc, HMETAFILE hmf, EnumMetaFileProc proc, [Optional] IntPtr param); /// The GdiComment function copies a comment from a buffer into a specified enhanced-format metafile. /// A handle to an enhanced-metafile device context. /// The length of the comment buffer, in bytes. /// A pointer to the buffer that contains the comment. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// /// A comment can include any kind of private information, for example, the source of a picture and the date it was created. A /// comment should begin with an application signature, followed by the data. /// /// /// Comments should not contain application-specific or position-specific data. Position-specific data specifies the location of a /// record, and it should not be included because one metafile may be embedded within another metafile. /// /// /// A public comment is a comment that begins with the comment signature identifier GDICOMMENT_IDENTIFIER. The following public /// comments are defined. /// /// /// /// GDICOMMENT_WINDOWS_METAFILE /// /// The GDICOMMENT_WINDOWS_METAFILE public comment contains a Windows-format metafile that is equivalent to an enhanced-format /// metafile. This comment is written only by the SetWinMetaFileBits function. The comment record, if given, follows the /// ENHMETAHEADER metafile record. The comment has the following form: /// /// /// /// /// /// GDICOMMENT_BEGINGROUP /// /// The GDICOMMENT_BEGINGROUP public comment identifies the beginning of a group of drawing records. It identifies an object within /// an enhanced metafile. The comment has the following form: /// /// /// /// /// /// GDICOMMENT_ENDGROUP /// /// The GDICOMMENT_ENDGROUP public comment identifies the end of a group of drawing records. The GDICOMMENT_BEGINGROUP comment and /// the GDICOMMENT_ENDGROUP comment must be included in a pair and may be nested. The comment has the following form: /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-gdicomment BOOL GdiComment( HDC hdc, UINT nSize, const BYTE // *lpData ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "80ed11fc-89f8-47ab-8b3b-c817733bd385")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GdiComment(HDC hdc, uint nSize, [In] byte[] lpData); /// /// /// The GetEnhMetaFile function creates a handle that identifies the enhanced-format metafile stored in the specified file. /// /// /// /// A pointer to a null-terminated string that specifies the name of an enhanced metafile. /// /// /// If the function succeeds, the return value is a handle to the enhanced metafile. /// If the function fails, the return value is NULL. /// /// /// /// When the application no longer needs an enhanced-metafile handle, it should delete the handle by calling the DeleteEnhMetaFile function. /// /// /// A Windows-format metafile must be converted to the enhanced format before it can be processed by the GetEnhMetaFile /// function. To convert the file, use the SetWinMetaFileBits function. /// /// /// Where text arguments must use Unicode characters, use this function as a wide-character function. Where text arguments must use /// characters from the Windows character set, use this function as an ANSI function. /// /// Examples /// For an example, see Opening an Enhanced Metafile and Displaying Its Contents. /// // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getenhmetafilea HENHMETAFILE GetEnhMetaFileA( LPCSTR lpName ); [DllImport(Lib.Gdi32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wingdi.h", MSDNShortId = "bcb9611e-8e4e-4f87-8a1e-dedbe0042821")] public static extern SafeHENHMETAFILE GetEnhMetaFile(string lpName); /// /// The GetEnhMetaFileBits function retrieves the contents of the specified enhanced-format metafile and copies them into a buffer. /// /// A handle to the enhanced metafile. /// The size, in bytes, of the buffer to receive the data. /// /// A pointer to a buffer that receives the metafile data. The buffer must be sufficiently large to contain the data. If lpbBuffer is /// NULL, the function returns the size necessary to hold the data. /// /// /// /// If the function succeeds and the buffer pointer is NULL, the return value is the size of the enhanced metafile, in bytes. /// /// /// If the function succeeds and the buffer pointer is a valid pointer, the return value is the number of bytes copied to the buffer. /// /// If the function fails, the return value is zero. /// /// /// /// After the enhanced-metafile bits are retrieved, they can be used to create a memory-based metafile by calling the /// SetEnhMetaFileBits function. /// /// /// The GetEnhMetaFileBits function does not invalidate the enhanced-metafile handle. The application must call the /// DeleteEnhMetaFile function to delete the handle when it is no longer needed. /// /// /// The metafile contents retrieved by this function are in the enhanced format. To retrieve the metafile contents in the Windows /// format, use the GetWinMetaFileBits function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getenhmetafilebits UINT GetEnhMetaFileBits( HENHMETAFILE hEMF, // UINT nSize, LPBYTE lpData ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "2bbfa0da-5b1e-4843-9777-c2e4c5fd3b78")] public static extern uint GetEnhMetaFileBits(HENHMETAFILE hEMF, uint nSize, byte[] lpData); /// /// The GetEnhMetaFileDescription function retrieves an optional text description from an enhanced-format metafile and copies /// the string to the specified buffer. /// /// A handle to the enhanced metafile. /// The size, in characters, of the buffer to receive the data. Only this many characters will be copied. /// A pointer to a buffer that receives the optional text description. /// /// /// If the optional text description exists and the buffer pointer is NULL, the return value is the length of the text string, /// in characters. /// /// /// If the optional text description exists and the buffer pointer is a valid pointer, the return value is the number of characters /// copied into the buffer. /// /// If the optional text description does not exist, the return value is zero. /// If the function fails, the return value is GDI_ERROR. /// /// /// /// The optional text description contains two strings, the first identifying the application that created the enhanced metafile and /// the second identifying the picture contained in the metafile. The strings are separated by a null character and terminated with /// two null charactersfor example, "XYZ Graphics Editor\0Bald Eagle\0\0" where \0 represents the null character. /// /// /// Where text arguments must use Unicode characters, use this function as a wide-character function. Where text arguments must use /// characters from the Windows character set, use this function as an ANSI function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getenhmetafiledescriptiona UINT GetEnhMetaFileDescriptionA( // HENHMETAFILE hemf, UINT cchBuffer, LPSTR lpDescription ); [DllImport(Lib.Gdi32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wingdi.h", MSDNShortId = "51f4f617-fe53-4463-b222-cb6860d15dd6")] public static extern uint GetEnhMetaFileDescription(HENHMETAFILE hemf, uint cchBuffer, StringBuilder lpDescription); /// /// The GetEnhMetaFileHeader function retrieves the record containing the header for the specified enhanced-format metafile. /// /// A handle to the enhanced metafile for which the header is to be retrieved. /// The size, in bytes, of the buffer to receive the data. Only this many bytes will be copied. /// /// A pointer to an ENHMETAHEADER structure that receives the header record. If this parameter is NULL, the function returns /// the size of the header record. /// /// /// If the function succeeds and the structure pointer is NULL, the return value is the size of the record that contains the /// header; if the structure pointer is a valid pointer, the return value is the number of bytes copied. Otherwise, it is zero. /// /// /// /// An enhanced-metafile header contains such information as the metafile's size, in bytes; the dimensions of the picture stored in /// the metafile; the number of records stored in the metafile; the offset to the optional text description; the size of the optional /// palette, and the resolution of the device on which the picture was created. /// /// The record that contains the enhanced-metafile header is always the first record in the metafile. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getenhmetafileheader UINT GetEnhMetaFileHeader( HENHMETAFILE // hemf, UINT nSize, LPENHMETAHEADER lpEnhMetaHeader ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "c42bcbe2-2e8f-42bd-a8e3-2827c6563300")] public static extern uint GetEnhMetaFileHeader(HENHMETAFILE hemf, uint nSize, IntPtr lpEnhMetaHeader); /// /// The GetEnhMetaFileHeader function retrieves the record containing the header for the specified enhanced-format metafile. /// /// A handle to the enhanced metafile for which the header is to be retrieved. /// An ENHMETAHEADER structure with the header record. /// /// /// An enhanced-metafile header contains such information as the metafile's size, in bytes; the dimensions of the picture stored in /// the metafile; the number of records stored in the metafile; the offset to the optional text description; the size of the optional /// palette, and the resolution of the device on which the picture was created. /// /// The record that contains the enhanced-metafile header is always the first record in the metafile. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getenhmetafileheader UINT GetEnhMetaFileHeader( HENHMETAFILE // hemf, UINT nSize, LPENHMETAHEADER lpEnhMetaHeader ); [PInvokeData("wingdi.h", MSDNShortId = "c42bcbe2-2e8f-42bd-a8e3-2827c6563300")] public static ENHMETAHEADER GetEnhMetaFileHeader(HENHMETAFILE hemf) { var hdr = ENHMETAHEADER.Default; using (var mem = SafeHGlobalHandle.CreateFromStructure(hdr)) { if (GetEnhMetaFileHeader(hemf, hdr.nSize, mem) != hdr.nSize) Win32Error.ThrowLastError(); return mem.ToStructure(); } } /// /// The GetEnhMetaFilePaletteEntries function retrieves optional palette entries from the specified enhanced metafile. /// /// A handle to the enhanced metafile. /// The number of entries to be retrieved from the optional palette. /// /// A pointer to an array of PALETTEENTRY structures that receives the palette colors. The array must contain at least as many /// structures as there are entries specified by the cEntries parameter. /// /// /// If the array pointer is NULL and the enhanced metafile contains an optional palette, the return value is the number of /// entries in the enhanced metafile's palette; if the array pointer is a valid pointer and the enhanced metafile contains an /// optional palette, the return value is the number of entries copied; if the metafile does not contain an optional palette, the /// return value is zero. Otherwise, the return value is GDI_ERROR. /// /// /// /// An application can store an optional palette in an enhanced metafile by calling the CreatePalette and SetPaletteEntries functions /// before creating the picture and storing it in the metafile. By doing this, the application can achieve consistent colors when the /// picture is displayed on a variety of devices. /// /// /// An application that displays a picture stored in an enhanced metafile can call the GetEnhMetaFilePaletteEntries function /// to determine whether the optional palette exists. If it does, the application can call the GetEnhMetaFilePaletteEntries /// function a second time to retrieve the palette entries and then create a logical palette (by using the CreatePalette function), /// select it into its device context (by using the SelectPalette function), and then realize it (by using the RealizePalette /// function). After the logical palette has been realized, calling the PlayEnhMetaFile function displays the picture using its /// original colors. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getenhmetafilepaletteentries UINT // GetEnhMetaFilePaletteEntries( HENHMETAFILE hemf, UINT nNumEntries, LPPALETTEENTRY lpPaletteEntries ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "2d61fd6a-cebd-457e-ad00-d3e8bd15584a")] public static extern uint GetEnhMetaFilePaletteEntries(HENHMETAFILE hemf, uint nNumEntries, [Out] PALETTEENTRY[] lpPaletteEntries); /// /// [GetMetaFile is no longer available for use as of Windows 2000. Instead, use GetEnhMetaFile.] /// The GetMetaFile function creates a handle that identifies the metafile stored in the specified file. /// /// A pointer to a null-terminated string that specifies the name of a metafile. /// /// If the function succeeds, the return value is a handle to the metafile. /// If the function fails, the return value is NULL. /// /// /// This function is not implemented in the Win32 API. It is provided for compatibility with 16-bit versions of Windows. In Win32 /// applications, use the GetEnhMetaFile function. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getmetafilea HMETAFILE GetMetaFileA( LPCSTR lpName ); [DllImport(Lib.Gdi32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("wingdi.h", MSDNShortId = "56A602C4-AE4D-46DE-B5DA-66A68E3A16BF")] public static extern SafeHMETAFILE GetMetaFile(string lpName); /// /// /// The GetMetaFileBitsEx function retrieves the contents of a Windows-format metafile and copies them into the specified buffer. /// /// /// Note This function is provided only for compatibility with Windows-format metafiles. Enhanced-format metafiles provide /// superior functionality and are recommended for new applications. The corresponding function for an enhanced-format metafile is GetEnhMetaFileBits. /// /// /// A handle to a Windows-format metafile. /// The size, in bytes, of the buffer to receive the data. /// /// A pointer to a buffer that receives the metafile data. The buffer must be sufficiently large to contain the data. If lpvData is /// NULL, the function returns the number of bytes required to hold the data. /// /// /// /// If the function succeeds and the buffer pointer is NULL, the return value is the number of bytes required for the buffer; /// if the function succeeds and the buffer pointer is a valid pointer, the return value is the number of bytes copied. /// /// If the function fails, the return value is zero. /// /// /// /// After the Windows-metafile bits are retrieved, they can be used to create a memory-based metafile by calling the /// SetMetaFileBitsEx function. /// /// /// The GetMetaFileBitsEx function does not invalidate the metafile handle. An application must delete this handle by calling /// the DeleteMetaFile function. /// /// To convert a Windows-format metafile into an enhanced-format metafile, use the SetWinMetaFileBits function. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getmetafilebitsex UINT GetMetaFileBitsEx( HMETAFILE hMF, UINT // cbBuffer, LPVOID lpData ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "6ca6de2e-79cb-4503-a0d7-f616b8e383eb")] public static extern uint GetMetaFileBitsEx(HMETAFILE hMF, uint cbBuffer, [In, Optional] byte[] lpData); /// /// The GetWinMetaFileBits function converts the enhanced-format records from a metafile into Windows-format records and /// stores the converted records in the specified buffer. /// /// A handle to the enhanced metafile. /// The size, in bytes, of the buffer into which the converted records are to be copied. /// /// A pointer to the buffer that receives the converted records. If lpbBuffer is NULL, GetWinMetaFileBits returns the /// number of bytes required to store the converted metafile records. /// /// The mapping mode to use in the converted metafile. /// A handle to the reference device context. /// /// /// If the function succeeds and the buffer pointer is NULL, the return value is the number of bytes required to store the /// converted records; if the function succeeds and the buffer pointer is a valid pointer, the return value is the size of the /// metafile data in bytes. /// /// If the function fails, the return value is zero. /// /// /// /// This function converts an enhanced metafile into a Windows-format metafile so that its picture can be displayed in an application /// that recognizes the older format. /// /// The system uses the reference device context to determine the resolution of the converted metafile. /// /// The GetWinMetaFileBits function does not invalidate the enhanced metafile handle. An application should call the /// DeleteEnhMetaFile function to release the handle when it is no longer needed. /// /// To create a scalable Windows-format metafile, specify MM_ANISOTROPIC as the fnMapMode parameter. /// The upper-left corner of the metafile picture is always mapped to the origin of the reference device. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getwinmetafilebits UINT GetWinMetaFileBits( HENHMETAFILE hemf, // UINT cbData16, LPBYTE pData16, INT iMapMode, HDC hdcRef ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "db61ea3a-44d0-4769-acb4-05a982d3f06f")] public static extern uint GetWinMetaFileBits(HENHMETAFILE hemf, uint cbData16, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] pData16, MapMode iMapMode, HDC hdcRef); /// The PlayEnhMetaFile function displays the picture stored in the specified enhanced-format metafile. /// A handle to the device context for the output device on which the picture will appear. /// A handle to the enhanced metafile. /// /// A pointer to a RECT structure that contains the coordinates of the bounding rectangle used to display the picture. The /// coordinates are specified in logical units. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// /// When an application calls the PlayEnhMetaFile function, the system uses the picture frame in the enhanced-metafile header /// to map the picture onto the rectangle pointed to by the lpRect parameter. (This picture may be sheared or rotated by setting the /// world transform in the output device before calling PlayEnhMetaFile.) Points along the edges of the rectangle are included /// in the picture. /// /// /// An enhanced-metafile picture can be clipped by defining the clipping region in the output device before playing the enhanced metafile. /// /// /// If an enhanced metafile contains an optional palette, an application can achieve consistent colors by setting up a color palette /// on the output device before calling PlayEnhMetaFile. To retrieve the optional palette, use the /// GetEnhMetaFilePaletteEntries function. /// /// /// An enhanced metafile can be embedded in a newly created enhanced metafile by calling PlayEnhMetaFile and playing the /// source enhanced metafile into the device context for the new enhanced metafile. /// /// /// The states of the output device context are preserved by this function. Any object created but not deleted in the enhanced /// metafile is deleted by this function. /// /// /// To stop this function, an application can call the CancelDC function from another thread to terminate the operation. In this /// case, the function returns FALSE. /// /// Examples /// For an example, see Opening an Enhanced Metafile and Displaying Its Contents. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-playenhmetafile BOOL PlayEnhMetaFile( HDC hdc, HENHMETAFILE // hmf, const RECT *lprect ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "51e8937b-0c42-49fe-8930-7af303fce788")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool PlayEnhMetaFile(HDC hdc, HENHMETAFILE hmf, [In, Optional] PRECT lprect); /// /// The PlayEnhMetaFileRecord function plays an enhanced-metafile record by executing the graphics device interface (GDI) /// functions identified by the record. /// /// A handle to the device context passed to the EnumEnhMetaFile function. /// /// A pointer to a table of handles to GDI objects used when playing the metafile. The first entry in this table contains the /// enhanced-metafile handle. /// /// A pointer to the enhanced-metafile record to be played. /// The number of handles in the handle table. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// This is an enhanced-metafile function. /// /// An application typically uses PlayEnhMetaFileRecord in conjunction with the EnumEnhMetaFile function to process and play /// an enhanced-format metafile one record at a time. /// /// /// The hdc, lpHandletable, and nHandles parameters must be exactly those passed to the EnhMetaFileProc callback procedure by the /// EnumEnhMetaFile function. /// /// If PlayEnhMetaFileRecord does not recognize a record, it ignores the record and returns TRUE. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-playenhmetafilerecord BOOL PlayEnhMetaFileRecord( HDC hdc, // LPHANDLETABLE pht, const ENHMETARECORD *pmr, UINT cht ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "3eec8c8d-b99f-4500-9d18-b819c097f341")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool PlayEnhMetaFileRecord(HDC hdc, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] HGDIOBJ[] pht, [In] ENHMETARECORD pmr, uint cht); /// /// The PlayMetaFile function displays the picture stored in the given Windows-format metafile on the specified device. /// /// Note This function is provided only for compatibility with Windows-format metafiles. Enhanced-format metafiles provide /// superior functionality and are recommended for new applications. The corresponding function for an enhanced-format metafile is PlayEnhMetaFile. /// /// /// Handle to a device context. /// Handle to a Windows-format metafile. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// To convert a Windows-format metafile into an enhanced format metafile, use the SetWinMetaFileBits function. /// A Windows-format metafile can be played multiple times. /// /// A Windows-format metafile can be embedded in a second Windows-format metafile by calling the PlayMetaFile function and /// playing the source metafile into the device context for the target metafile. /// /// Any object created but not deleted in the Windows-format metafile is deleted by this function. /// /// To stop this function, an application can call the CancelDC function from another thread to terminate the operation. In this /// case, the function returns FALSE. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-playmetafile BOOL PlayMetaFile( HDC hdc, HMETAFILE hmf ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "044894df-dc8a-41b2-8810-e0a1b8bc19d8")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool PlayMetaFile(HDC hdc, HMETAFILE hmf); /// /// /// The PlayMetaFileRecord function plays a Windows-format metafile record by executing the graphics device interface (GDI) /// function contained within that record. /// /// /// Note This function is provided only for compatibility with Windows-format metafiles. Enhanced-format metafiles provide /// superior functionality and are recommended for new applications. The corresponding function for an enhanced-format metafile is PlayEnhMetaFileRecord. /// /// /// A handle to a device context. /// /// A pointer to a HANDLETABLE structure representing the table of handles to GDI objects used when playing the metafile. /// /// A pointer to the Windows-format metafile record. /// The number of handles in the handle table. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// To convert a Windows-format metafile into an enhanced-format metafile, use the SetWinMetaFileBits function. /// /// An application typically uses PlayMetaFileRecord in conjunction with the EnumMetaFile function to process and play a /// Windows-format metafile one record at a time. /// /// /// The lpHandletable and nHandles parameters must be identical to those passed to the EnumMetaFileProc callback procedure by EnumMetaFile. /// /// If the PlayMetaFileRecord function does not recognize a record, it ignores the record and returns TRUE. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-playmetafilerecord BOOL PlayMetaFileRecord( HDC hdc, // LPHANDLETABLE lpHandleTable, LPMETARECORD lpMR, UINT noObjs ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "bea22981-dc77-4de2-b6dc-d6a4f4b74bbd")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool PlayMetaFileRecord(HDC hdc, [In] HGDIOBJ[] lpHandleTable, METARECORD lpMR, uint noObjs); /// The SetEnhMetaFileBits function creates a memory-based enhanced-format metafile from the specified data. /// Specifies the size, in bytes, of the data provided. /// /// Pointer to a buffer that contains enhanced-metafile data. (It is assumed that the data in the buffer was obtained by calling the /// GetEnhMetaFileBits function.) /// /// /// If the function succeeds, the return value is a handle to a memory-based enhanced metafile. /// If the function fails, the return value is NULL. /// /// /// /// When the application no longer needs the enhanced-metafile handle, it should delete the handle by calling the DeleteEnhMetaFile function. /// /// /// The SetEnhMetaFileBits function does not accept metafile data in the Windows format. To import Windows-format metafiles, /// use the SetWinMetaFileBits function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setenhmetafilebits HENHMETAFILE SetEnhMetaFileBits( UINT // nSize, const BYTE *pb ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "0f21ed97-e37f-4b44-a2eb-b8e284b3dc4b")] public static extern SafeHENHMETAFILE SetEnhMetaFileBits(uint nSize, [In] byte[] pb); /// /// The SetMetaFileBitsEx function creates a memory-based Windows-format metafile from the supplied data. /// /// Note This function is provided only for compatibility with Windows-format metafiles. Enhanced-format metafiles provide /// superior functionality and are recommended for new applications. The corresponding function for an enhanced-format metafile is SetEnhMetaFileBits. /// /// /// Specifies the size, in bytes, of the Windows-format metafile. /// /// Pointer to a buffer that contains the Windows-format metafile. (It is assumed that the data was obtained by using the /// GetMetaFileBitsEx function.) /// /// /// If the function succeeds, the return value is a handle to a memory-based Windows-format metafile. /// If the function fails, the return value is NULL. /// /// /// To convert a Windows-format metafile into an enhanced-format metafile, use the SetWinMetaFileBits function. /// /// When the application no longer needs the metafile handle returned by SetMetaFileBitsEx, it should delete it by calling the /// DeleteMetaFile function. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setmetafilebitsex HMETAFILE SetMetaFileBitsEx( UINT cbBuffer, // const BYTE *lpData ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "232eeba9-f579-4b5f-a31a-416aeb56a909")] public static extern SafeHMETAFILE SetMetaFileBitsEx(uint cbBuffer, [In] byte[] lpData); /// /// The SetWinMetaFileBits function converts a metafile from the older Windows format to the new enhanced format and stores /// the new metafile in memory. /// /// The size, in bytes, of the buffer that contains the Windows-format metafile. /// /// A pointer to a buffer that contains the Windows-format metafile data. (It is assumed that the data was obtained by using the /// GetMetaFileBitsEx or GetWinMetaFileBits function.) /// /// A handle to a reference device context. /// /// A pointer to a METAFILEPICT structure that contains the suggested size of the metafile picture and the mapping mode that was used /// when the picture was created. /// /// /// If the function succeeds, the return value is a handle to a memory-based enhanced metafile. /// If the function fails, the return value is NULL. /// /// /// /// Windows uses the reference device context's resolution data and the data in the METAFILEPICT structure to scale a picture. If the /// hdcRef parameter is NULL, the system uses resolution data for the current output device. If the lpmfp parameter is /// NULL, the system uses the MM_ANISOTROPIC mapping mode to scale the picture so that it fits the entire device surface. The /// hMF member of the METAFILEPICT structure is not used. /// /// /// When the application no longer needs the enhanced metafile handle, it should delete it by calling the DeleteEnhMetaFile function. /// /// The handle returned by this function can be used with other enhanced-metafile functions. /// /// If the reference device context is not identical to the device in which the metafile was originally created, some GDI functions /// that use device units may not draw the picture correctly. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setwinmetafilebits HENHMETAFILE SetWinMetaFileBits( UINT // nSize, const BYTE *lpMeta16Data, HDC hdcRef, const METAFILEPICT *lpMFP ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "b7170c8a-da5f-4946-9c56-da3cffc84567")] public static extern SafeHENHMETAFILE SetWinMetaFileBits(uint nSize, [In] byte[] lpMeta16Data, [Optional] HDC hdcRef, in METAFILEPICT lpMFP); /// /// The SetWinMetaFileBits function converts a metafile from the older Windows format to the new enhanced format and stores /// the new metafile in memory. /// /// The size, in bytes, of the buffer that contains the Windows-format metafile. /// /// A pointer to a buffer that contains the Windows-format metafile data. (It is assumed that the data was obtained by using the /// GetMetaFileBitsEx or GetWinMetaFileBits function.) /// /// A handle to a reference device context. /// /// A pointer to a METAFILEPICT structure that contains the suggested size of the metafile picture and the mapping mode that was used /// when the picture was created. /// /// /// If the function succeeds, the return value is a handle to a memory-based enhanced metafile. /// If the function fails, the return value is NULL. /// /// /// /// Windows uses the reference device context's resolution data and the data in the METAFILEPICT structure to scale a picture. If the /// hdcRef parameter is NULL, the system uses resolution data for the current output device. If the lpmfp parameter is /// NULL, the system uses the MM_ANISOTROPIC mapping mode to scale the picture so that it fits the entire device surface. The /// hMF member of the METAFILEPICT structure is not used. /// /// /// When the application no longer needs the enhanced metafile handle, it should delete it by calling the DeleteEnhMetaFile function. /// /// The handle returned by this function can be used with other enhanced-metafile functions. /// /// If the reference device context is not identical to the device in which the metafile was originally created, some GDI functions /// that use device units may not draw the picture correctly. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setwinmetafilebits HENHMETAFILE SetWinMetaFileBits( UINT // nSize, const BYTE *lpMeta16Data, HDC hdcRef, const METAFILEPICT *lpMFP ); [DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)] [PInvokeData("wingdi.h", MSDNShortId = "b7170c8a-da5f-4946-9c56-da3cffc84567")] public static extern SafeHENHMETAFILE SetWinMetaFileBits(uint nSize, [In] byte[] lpMeta16Data, [Optional] HDC hdcRef, [Optional] IntPtr lpMFP); /// /// /// The ENHMETAHEADER structure contains enhanced-metafile data such as the dimensions of the picture stored in the enhanced /// metafile, the count of records in the enhanced metafile, the resolution of the device on which the picture was created, and so on. /// /// This structure is always the first record in an enhanced metafile. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-enhmetaheader typedef struct tagENHMETAHEADER { DWORD iType; // DWORD nSize; RECTL rclBounds; RECTL rclFrame; DWORD dSignature; DWORD nVersion; DWORD nBytes; DWORD nRecords; WORD nHandles; WORD // sReserved; DWORD nDescription; DWORD offDescription; DWORD nPalEntries; SIZEL szlDevice; SIZEL szlMillimeters; DWORD // cbPixelFormat; DWORD offPixelFormat; DWORD bOpenGL; SIZEL szlMicrometers; } ENHMETAHEADER, *PENHMETAHEADER, *LPENHMETAHEADER; [PInvokeData("wingdi.h", MSDNShortId = "8e5f9a51-a995-48be-b936-1766fccb603a")] [StructLayout(LayoutKind.Sequential)] public struct ENHMETAHEADER { /// The record type. This member must specify the value assigned to the EMR_HEADER constant. public RecordType iType; /// The structure size, in bytes. public uint nSize; /// /// The dimensions, in device units, of the smallest rectangle that can be drawn around the picture stored in the metafile. This /// rectangle is supplied by graphics device interface (GDI). Its dimensions include the right and bottom edges. /// public RECT rclBounds; /// /// The dimensions, in .01 millimeter units, of a rectangle that surrounds the picture stored in the metafile. This rectangle /// must be supplied by the application that creates the metafile. Its dimensions include the right and bottom edges. /// public RECT rclFrame; /// A signature. This member must specify the value assigned to the ENHMETA_SIGNATURE constant. public uint dSignature; /// The metafile version. The current version value is 0x10000. public uint nVersion; /// The size of the enhanced metafile, in bytes. public uint nBytes; /// The number of records in the enhanced metafile. public uint nRecords; /// The number of handles in the enhanced-metafile handle table. (Index zero in this table is reserved.) public ushort nHandles; /// Reserved; must be zero. public ushort sReserved; /// /// The number of characters in the array that contains the description of the enhanced metafile's contents. This member should /// be set to zero if the enhanced metafile does not contain a description string. /// public uint nDescription; /// /// The offset from the beginning of the ENHMETAHEADER structure to the array that contains the description of the /// enhanced metafile's contents. This member should be set to zero if the enhanced metafile does not contain a description string. /// public uint offDescription; /// The number of entries in the enhanced metafile's palette. public uint nPalEntries; /// The resolution of the reference device, in pixels. public SIZE szlDevice; /// The resolution of the reference device, in millimeters. public SIZE szlMillimeters; /// /// The size of the last recorded pixel format in a metafile. If a pixel format is set in a reference DC at the start of /// recording, cbPixelFormat is set to the size of the PIXELFORMATDESCRIPTOR. When no pixel format is set when a metafile is /// recorded, this member is set to zero. If more than a single pixel format is set, the header points to the last pixel format. /// public uint cbPixelFormat; /// /// The offset of pixel format used when recording a metafile. If a pixel format is set in a reference DC at the start of /// recording or during recording, offPixelFormat is set to the offset of the PIXELFORMATDESCRIPTOR in the metafile. If no pixel /// format is set when a metafile is recorded, this member is set to zero. If more than a single pixel format is set, the header /// points to the last pixel format. /// public uint offPixelFormat; /// /// Indicates whether any OpenGL records are present in a metafile. bOpenGL is a simple Boolean flag that you can use to /// determine whether an enhanced metafile requires OpenGL handling. When a metafile contains OpenGL records, bOpenGL is /// TRUE; otherwise it is FALSE. /// [MarshalAs(UnmanagedType.Bool)] public bool bOpenGL; /// The size of the reference device, in micrometers. public SIZE szlMicrometers; /// A default instance of the structure with the size field preset. public static readonly ENHMETAHEADER Default = new ENHMETAHEADER { nSize = (uint)Marshal.SizeOf(typeof(ENHMETAHEADER)) }; } /// /// The HANDLETABLE structure is an array of handles, each of which identifies a graphics device interface (GDI) object. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-handletable typedef struct tagHANDLETABLE { HGDIOBJ // objectHandle[1]; } HANDLETABLE, *PHANDLETABLE, *LPHANDLETABLE; [PInvokeData("wingdi.h", MSDNShortId = "c0c03c7d-baac-4b59-ba2f-8f6330651b49")] [StructLayout(LayoutKind.Sequential)] public struct HANDLETABLE { /// An array of handles. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public HGDIOBJ[] objectHandle; } /// Defines the metafile picture format used for exchanging metafile data through the clipboard. // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-metafilepict typedef struct tagMETAFILEPICT { LONG mm; LONG // xExt; LONG yExt; HMETAFILE hMF; } METAFILEPICT, *LPMETAFILEPICT; [PInvokeData("wingdi.h")] [StructLayout(LayoutKind.Sequential)] public struct METAFILEPICT { /// /// Type: LONG /// The mapping mode in which the picture is drawn. /// public MapMode mm; /// /// Type: LONG /// /// The size of the metafile picture for all modes except the MM_ISOTROPIC and MM_ANISOTROPIC modes. (For more /// information about these modes, see the yExt member.) The x-extent specifies the width of the rectangle within which /// the picture is drawn. The coordinates are in units that correspond to the mapping mode. /// /// public int xExt; /// /// Type: LONG /// /// The size of the metafile picture for all modes except the MM_ISOTROPIC and MM_ANISOTROPIC modes. The y-extent /// specifies the height of the rectangle within which the picture is drawn. The coordinates are in units that correspond to the /// mapping mode. For MM_ISOTROPIC and MM_ANISOTROPIC modes, which can be scaled, the xExt and yExt /// members contain an optional suggested size in MM_HIMETRIC units. For MM_ANISOTROPIC pictures, xExt and /// yExt can be zero when no suggested size is supplied. For MM_ISOTROPIC pictures, an aspect ratio must be /// supplied even when no suggested size is given. (If a suggested size is given, the aspect ratio is implied by the size.) To /// give an aspect ratio without implying a suggested size, set xExt and yExt to negative values whose ratio is the /// appropriate aspect ratio. The magnitude of the negative xExt and yExt values is ignored; only the ratio is used. /// /// public int yExt; /// /// Type: HMETAFILE /// A handle to a memory metafile. /// public HMETAFILE hMF; } /// /// The ENHMETARECORD structure contains data that describes a graphics device interface (GDI) function used to create part of /// a picture in an enhanced-format metafile. /// // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-enhmetarecord typedef struct tagENHMETARECORD { DWORD iType; // DWORD nSize; DWORD dParm[1]; } ENHMETARECORD, *PENHMETARECORD, *LPENHMETARECORD; [PInvokeData("wingdi.h", MSDNShortId = "efe49094-fe61-40e1-873e-3302c595717e")] public class ENHMETARECORD : SafeNativeArray { /// Initializes a new instance of the class. /// The record type. /// An array of parameters passed to the GDI function identified by the record. public ENHMETARECORD(RecordType type, uint[] parameters) : base(parameters, 8) { handle.Write(type); handle.Write((uint)Size, 4); } /// Initializes a new instance of the class. private ENHMETARECORD(IntPtr ptr) : base(ptr, 0, false, 8, 0, true) { sz = handle.ToStructure(0, 4); base.Count = (int)(Size - base.HeaderSize) / 4; } /// An array of parameters passed to the GDI function identified by the record. public uint[] dParm => base.Elements; /// The record type. public RecordType iType => handle.ToStructure(); /// The size of the record, in bytes. public uint nSize => Size; /// Performs an explicit conversion from to . /// The pointer to an instance. /// The result of the conversion. public static explicit operator ENHMETARECORD(IntPtr ptr) => new ENHMETARECORD(ptr); } /// The METARECORD structure contains a Windows-format metafile record. // https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-metarecord typedef struct tagMETARECORD { DWORD rdSize; WORD // rdFunction; WORD rdParm[1]; } METARECORD, *PMETARECORD, *LPMETARECORD; [PInvokeData("wingdi.h", MSDNShortId = "7c5d6e97-dff1-4c80-a7d3-082413dca469")] public class METARECORD : SafeNativeArray { /// Initializes a new instance of the class. /// The function number. /// An array of parameters passed to the GDI function identified by the record. public METARECORD(ushort functionNumber, ushort[] parameters) : base(parameters, 6) { handle.Write(Size / 2U); handle.Write(functionNumber, 4); } /// Initializes a new instance of the class. private METARECORD(IntPtr ptr) : base(ptr, 0, false, 6, 0, true) { sz = handle.ToStructure() * 2U; base.Count = (int)(Size - base.HeaderSize) / 2; } /// The function number. public ushort rdFunction => handle.ToStructure(Size, 4); /// An array of words containing the function parameters, in reverse of the order they are passed to the function. public ushort[] rdParm => base.Elements; /// The size, in words, of the record. public uint rdSize => Size / 2U; /// Performs an explicit conversion from to . /// The pointer to an instance. /// The result of the conversion. public static explicit operator METARECORD(IntPtr ptr) => new METARECORD(ptr); } /// Provides a for that is disposed using . public class SafeHENHMETAFILE : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeHENHMETAFILE(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeHENHMETAFILE() : base() { } /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator HENHMETAFILE(SafeHENHMETAFILE h) => h.handle; /// protected override bool InternalReleaseHandle() => DeleteEnhMetaFile(this); } /// Provides a for that is disposed using . public class SafeHMETAFILE : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeHMETAFILE(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeHMETAFILE() : base() { } /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator HMETAFILE(SafeHMETAFILE h) => h.handle; /// protected override bool InternalReleaseHandle() => DeleteMetaFile(handle); } } }