TEnhMetaFile
Source: source/classes/tenhmeta.prg
Inherits from: TControl
TEnhMetaFile displays Windows Enhanced Metafiles (EMF) inside FiveWin windows and dialogs. It is a full TControl subclass supporting sizing, positioning, zoom in/out, shadow effects, and resource cleanup. EMF files contain vector graphics that scale without quality loss, making them ideal for diagrams, logos, and print-preview content.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
hMeta | Numeric (Handle) | Enhanced metafile handle (HENHMETAFILE) |
nWidth | Numeric | Logical width of the metafile |
nHeight | Numeric | Logical height of the metafile |
nXZoom | Numeric | X-axis zoom factor (default 2) |
nYZoom | Numeric | Y-axis zoom factor (default 4) |
nXorig | Numeric | X-axis scroll origin offset |
nYorig | Numeric | Y-axis scroll origin offset |
lZoom | Logical | Whether zoom mode is currently active |
lShadow | Logical | Show shadow effect around the control (default .T.) |
Methods
| Method | Description |
|---|---|
New( nTop, nLeft, nW, nH, cFile, oWnd ) | Create a new TEnhMetaFile control that loads and displays an EMF file |
Redefine( nId, cFile, oWnd ) | Redefine from a dialog resource template |
SetFile( cFile ) | Load a new EMF file, replacing the current one |
ZoomIn() | Zoom into the metafile (divides nWidth/nHeight by nXZoom/nYZoom) |
ZoomOut() | Zoom out of the metafile (restores original dimensions) |
SetZoomFactor( nX, nY ) | Change the zoom factor and adjust the current zoom state |
SetOrg( nX, nY ) | Set the scroll origin for panning the metafile view |
End() | Release the metafile handle and call the superclass End() |
EMF Command
TEnhMetaFile can be created directly using the EMF command syntax:
@ nRow, nCol EMF oEmf FILE cFile OF oWnd SIZE nW, nH
Example
#include "FiveWin.ch"
function Main()
local oWnd, oEmf
DEFINE WINDOW oWnd TITLE "EMF Viewer" SIZE 600, 500
@ 10, 10 EMF oEmf FILE "diagram.emf" OF oWnd SIZE 560, 400
oEmf:lShadow := .T.
// Button to zoom in
@ 420, 10 BUTTON "Zoom In" OF oWnd SIZE 80, 25 ;
ACTION oEmf:ZoomIn()
@ 420, 100 BUTTON "Zoom Out" OF oWnd SIZE 80, 25 ;
ACTION oEmf:ZoomOut()
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- TEnhMetaFile handles only Enhanced Metafiles (.emf). For WMF files with automatic conversion, use TMetaFile instead.
- The ZoomIn/ZoomOut methods toggle between zoomed and non-zoomed states. The zoom factor is set via
nXZoom(default 2) andnYZoom(default 4). - The shadow effect draws a 3D-like border shadow using a TPen. Disable by setting
lShadow := .F.. - Metafiles are loaded from file on first paint. Use
SetFile()to change the displayed file at runtime, which releases the previous metafile handle.