Newsgroup: it.comp.lang.visual-basic
Titolo: [?] wmf - api enummetafile


I work with VB4/32 and I would like to use API EnumMetafile to retrieve
single GDI commands from a WMF to a list control ? Can you help me?
Thanks for a response

 single GDI commands from a WMF to a list control ? Can you help me?
The EnumMetafile function in still referenced for back-end
campatibility. The new Enhanced Metafile format has superceded
then old (win3.x) Metafile definition. According to this,
you should use the Win32 EnumEnhMetaFile function and the
related EnhMetaFileProc callback function instead.
However, if you need to deal with the old meta format,
the example that follows defines a method to retrieve the
GDI functions from Windows-format metafile records :
--------------------------------------------------------
I'm reporting meta GDI Escapes only, since you can find
all meta GDI functions in the "constants" section of your
API Viewer, listed under the prefix META_***.
All Enhanced metafile record types are listed under the
prefix EMR_***
-----------------------------------------------------------
'Metafile GDI Escapes
Public Const NEWFRAME = 1
Public Const ABORTDOC = 2
Public Const NEXTBAND = 3
Public Const SETCOLORTABLE = 4
Public Const GETCOLORTABLE = 5
Public Const FLUSHOUTPUT = 6
Public Const DRAFTMODE = 7
Public Const QUERYESCSUPPORT = 8
Public Const SETABORTPROC = 9
Public Const STARTDOC = 10
Public Const ENDDOC = 11
Public Const GETPHYSPAGESIZE = 12
Public Const GETPRINTINGOFFSET = 13
Public Const GETSCALINGFACTOR = 14
Public Const MFCOMMENT = 15
Public Const GETPENWIDTH = 16
Public Const SETCOPYCOUNT = 17
Public Const SELECTPAPERSOURCE = 18
Public Const DEVICEDATA = 19
Public Const PASSTHROUGH = 19
Public Const GETTECHNOLGY = 20
Public Const GETTECHNOLOGY = 20
Public Const SETLINECAP = 21
Public Const SETLINEJOIN = 22
Public Const SETMITERLIMIT = 23
Public Const BANDINFO = 24
Public Const DRAWPATTERNRECT = 25
Public Const GETVECTORPENSIZE = 26
Public Const GETVECTORBRUSHSIZE = 27
Public Const ENABLEDUPLEX = 28
Public Const GETSETPAPERBINS = 29
Public Const GETSETPRINTORIENT = 30
Public Const ENUMPAPERBINS = 31
Public Const SETDIBSCALING = 32
Public Const EPSPRINTING = 33
Public Const ENUMPAPERMETRICS = 34
Public Const GETSETPAPERMETRICS = 35
Public Const POSTSCRIPT_DATA = 37
Public Const POSTSCRIPT_IGNORE = 38
Public Const MOUSETRAILS = 39
Public Const GETDEVICEUNITS = 42
Public Const GETEXTENDEDTEXTMETRICS = 256
Public Const GETEXTENTTABLE = 257
Public Const GETPAIRKERNTABLE = 258
Public Const GETTRACKKERNTABLE = 259
Public Const EXTTEXTOUT = 512
Public Const GETFACENAME = 513
Public Const DOWNLOADFACE = 514
Public Const ENABLERELATIVEWIDTHS = 768
Public Const ENABLEPAIRKERNING = 769
Public Const SETKERNTRACK = 770
Public Const SETALLJUSTVALUES = 771
Public Const SETCHARSET = 772
Public Const STRETCHBLT = 2048
Public Const GETSETSCREENPARAMS = 3072
Public Const QUERYDIBSUPPORT = 3073
Public Const BEGIN_PATH = 4096
Public Const CLIP_TO_PATH = 4097
Public Const END_PATH = 4098
Public Const EXT_DEVICE_CAPS = 4099
Public Const RESTORE_CTM = 4100
Public Const SAVE_CTM = 4101
Public Const SET_ARC_DIRECTION = 4102
Public Const SET_BACKGROUND_COLOR = 4103
Public Const SET_POLY_MODE = 4104
Public Const SET_SCREEN_ANGLE = 4105
Public Const SET_SPREAD = 4106
Public Const TRANSFORM_CTM = 4107
Public Const SET_CLIP_BOX = 4108
Public Const SET_BOUNDS = 4109
Public Const SET_MIRROR_MODE = 4110
Public Const OPENCHANNEL = 4110
Public Const DOWNLOADHEADER = 4111
Public Const CLOSECHANNEL = 4112
Public Const POSTSCRIPT_PASSTHROUGH = 4115
Public Const ENCAPSULATED_POSTSCRIPT = 4116
'new escape for NT5 pscript driver
Public Const POSTSCRIPT_IDENTIFY = 4117
'new escape for NT5 pscript driver
Public Const POSTSCRIPT_INJECTION = 4118
Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type
Type METARECORD
    mrSize As Long
    mrFunction As Integer
    mrdParm(3) As Integer
End Type
Declare Function EnumMetaFile Lib "gdi32" (ByVal hdc As Long, ByVal hMetafile As Long, ByVal lpMFEnumProc As Long, ByRef lParam As
XForm) As Long
Declare Function GetMetaFile Lib "gdi32" _
    Alias "GetMetaFileA" ( _
    ByVal lpFileName As String) As Long
Declare Function DeleteMetaFile Lib "gdi32" _
    (ByVal hMF As Long) As Long
Public Declare Function EnumMetaFile Lib "gdi32" _
    Alias "EnumMetaFile" ( _
    ByVal hDC As Long, _
    ByVal hMetafile As Long, _
    ByVal lpMFEnumProc As Long, _
    ByVal lParam As Long) As Long
Where:
- hDC is a Device Contest we are using for reference.
In most cases you should use Printer.hdc
- hMetafile is a meta handle retrieved by GetMetaFile()
- lpMFEnumProc is a pointer to an EnumMetaFileProc
callback function. This function is called for each record
that EnumMetaFile finds
- lParam points to optional data which is passed to the
callback function for you to use as you wish.
According to these definitions, you may use a prototype like this:
--- objhDC is the DC of the printer, in this case
--- ObjectList is a pointer to a HANDLETABLE record which
enumerates graphic objects used in the metafile (pens, brushes ecc.)
--- udtMetaRecord is a pointer to a METARECORD structure.
This is what we really need
--- numHandles is the number of object referenced in the
HANDLETABLE structure
--- MyData is a cudtom type. In most case, is used to pass to
the callback divisors and offsets for a SetViewportOrgEx func.
hMF = GetMetaFile(MetaPathAndName)
lngRet = EnumMetaFile(Printer.hdc, hMF, _
              AddressOf EnumMetaFileProc, MyRecord)
Public Function EnumMetaFileProc( _
    ByVal objhDC As Long, _
    ObjectList As Long, _
    ByRef udtMetaRecord As METARECORD, _
    ByVal numHandles As Long, _
    ByRef MyData As MyRecord) As Long
    'Add to the list the record number
    Form1.List1.AddItem "Record: " & Str$(MetaRec.rdFunction)
    'Now you have to add to your list the name of the functions
    'referenced by number.
    Select Case udtMetaRecord.rdFunction
        Case xxx
            'This is one of the numbered functions listed as META_*
            'ie Const META_BITBLT = &H922 is the "BitBlt" function
            Form1.List1.AddItem "FunctionName"
        Case Else
            'NOP
            ' If you want to stop the enumeration process,
            'you have to set EnumMetaFileProc = 0
    End Select
    'Continue the enumeration process
    EnumMetaFileProc = 1
End Function