Function Reference


Creates a device context for an enhanced-format metafile

#include <WinAPIGdi.au3>
_WinAPI_CreateEnhMetaFile ( [$hDC = 0 [, $tRECT = 0 [, $bPixels = False [, $sFilePath = '' [, $sDescription = '']]]]] )


$hDC [optional] Handle to a reference device for the enhanced metafile. The system uses this device context to record the resolution and units of the device on which a picture originally appeared.
If this parameter is 0 (Default), it uses the current display device for reference.
$tRECT [optional] $tagRECT structure that specifies the dimensions of the picture to be stored in the enhanced metafile.
If this parameter is 0 (Default), the graphics device interface computes the dimensions of the smallest rectangle that surrounds the picture drawn by the application.
$bPixels [optional] Specifies whether the $tRECT structure defined in pixels, valid values:
    True    - In logical units (pixels).
    False    - In .01-millimeter units (Default).
$sFilePath [optional] The file name for the enhanced metafile to be created.
If this parameter is '' (Default), the enhanced metafile is memory based and its contents are lost when it is deleted by using the _WinAPI_DeleteEnhMetaFile() function.
$sDescription [optional] The string that specifies the name of the application that created the picture, as well as the picture's title. This string must be an empty string or represented as follows:
    "application name|picture name"

Return Value

Success: Handle to the device context for the enhanced metafile.
Failure: 0.


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 _WinAPI_PlayEnhMetaFile() function.
When displaying the picture, the system uses the rectangle pointed to by the $tRECT parameter and the resolution data from the reference device to position and scale the picture.

The file name for the enhanced metafile should use the .emf extension.



See Also

Search CreateEnhMetaFile in MSDN Library.


#include <MsgBoxConstants.au3>
#include <WinAPIGdi.au3>

Local Const $sEmf = @TempDir & '\Test.emf'

If FileExists($sEmf) Then
    If MsgBox(BitOR($MB_YESNOCANCEL, $MB_ICONQUESTION, $MB_DEFBUTTON2, $MB_SYSTEMMODAL), 'Create Enhanced Metafile', $sEmf & ' is already exists.' & @CRLF & @CRLF & 'Do you want to replace it?') <> 6 Then
    If Not FileDelete($sEmf) Then
        MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Create Enhanced Metafile', 'Unable to delete file.')

; Create device context for an enhanced-format metafile
Local $tRECT = _WinAPI_CreateRect(0, 0, 250, 250)
Local $hDC = _WinAPI_CreateEnhMetaFile(0, $tRECT, 1, @TempDir & '\Test.emf')

; Draw objects
Local $hBrush = _WinAPI_SelectObject($hDC, _WinAPI_GetStockObject($DC_BRUSH))
Local $hPen = _WinAPI_SelectObject($hDC, _WinAPI_GetStockObject($NULL_PEN))
_WinAPI_SetDCBrushColor($hDC, 0xAA0000)
_WinAPI_Rectangle($hDC, $tRECT)
_WinAPI_SetDCBrushColor($hDC, 0xFFFFFF)
Local $aPoint[10][2] = [[0, 90], [95, 90], [125, 0], [154, 90], [250, 90], [172, 147], [202, 238], [125, 181], [47, 238], [77, 147]]
Local $hRgn = _WinAPI_CreatePolygonRgn($aPoint)
_WinAPI_OffsetRgn($hRgn, 0, 6)
_WinAPI_PaintRgn($hDC, $hRgn)

; Release objects
_WinAPI_SelectObject($hDC, $hBrush)
_WinAPI_SelectObject($hDC, $hPen)
Local $hEmf = _WinAPI_CloseEnhMetaFile($hDC)

; Show created .emf file into the Microsoft Paint
If FileExists($sEmf) Then
    ShellExecute(@SystemDir & '\mspaint.exe', $sEmf)