TMetaFile
Source: source/classes/tmetafil.prg
Inherits from: TControl
TMetaFile displays both Windows Metafiles (WMF) and Enhanced Metafiles (EMF) inside FiveWin windows and dialogs. It automatically detects WMF files and converts them to EMF format for display. TMetaFile offers the same zoom, pan, and shadow features as TEnhMetaFile, with additional support for mouse wheel scrolling and coordinate system management.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
hMeta | Numeric (Handle) | Metafile handle (HENHMETAFILE or HMETAFILE) |
nWidth | Numeric | Logical width |
nHeight | Numeric | Logical height |
nXZoom | Numeric | X-axis zoom factor (default 1) |
nYZoom | Numeric | Y-axis zoom factor (default 2) |
lZoom | Logical | Whether zoom mode is active |
lShadow | Logical | Show drop shadow (default .T.) |
bMouseWheel | Code block | Mouse wheel event handler |
nVRatio | Numeric | Vertical aspect ratio for viewport mapping |
Methods
| Method | Description |
|---|---|
New( nTop, nLeft, nW, nH, cFile, oWnd ) | Create a new TMetaFile control |
Redefine( nId, cFile, oWnd ) | Redefine from dialog resource |
SetFile( cFile ) | Load a new WMF or EMF file |
ZoomIn() | Zoom in (divides dimensions by nXZoom/nYZoom) |
ZoomOut() | Zoom out (restores original dimensions) |
SetZoomFactor( nX, nY ) | Change the zoom multipliers |
SetOrg( nX, nY ) | Set the scroll origin offset |
MouseWheel( nKey, nDelta, nXPos, nYPos ) | Handle mouse wheel events (delegates to bMouseWheel) |
End() | Release metafile handle and call superclass End() |
METAFILE Command
TMetaFile can be created directly using the METAFILE command syntax:
@ nRow, nCol METAFILE oMf FILE cFile OF oWnd SIZE nW, nH
Example
#include "FiveWin.ch"
function Main()
local oWnd, oMeta
DEFINE WINDOW oWnd TITLE "WMF Viewer" SIZE 600, 500
// Display a WMF file (auto-converted to EMF internally)
@ 10, 10 METAFILE oMeta FILE "drawing.wmf" OF oWnd SIZE 560, 400
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- TMetaFile handles both WMF and EMF formats. When a WMF file is loaded, it is automatically converted to EMF via the
WMF2EMF()function before display. - The coordinate system uses
MM_ANISOTROPICmapping mode for proper aspect ratio scaling. - Mouse wheel support allows interactive zooming. Assign a code block to
bMouseWheelto handle wheel events. nVRatiois calculated automatically from the control dimensions to maintain the correct aspect ratio during zoom operations.- The zoom factor defaults are 1 (X) and 2 (Y), differing from TEnhMetaFile's defaults of 2 and 4.