Jump to content

DdfMetafile

From EDM2
Revision as of 03:11, 14 May 2025 by Martini (talk | contribs) (Created page with "{{DISPLAYTITLE:DdfMetafile}} This function places a reference to a metafile into the DDF buffer. ==Syntax== DdfMetafile(hddf, hmf, prclRect) ==Parameters== ;hddf (HDDF) - input :Handle to DDF returned by DdfInitialize. ;hmf (HMF) - input :The handle of the metafile to display. ;prclRect (PRECTL) - input :Size of the rectangle. If not NULL, contains the size of the rectangle in which the metafile will be displayed. The aspect ratio of the metafile is ad...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


This function places a reference to a metafile into the DDF buffer.

Syntax

DdfMetafile(hddf, hmf, prclRect)

Parameters

hddf (HDDF) - input
Handle to DDF returned by DdfInitialize.
hmf (HMF) - input
The handle of the metafile to display.
prclRect (PRECTL) - input
Size of the rectangle. If not NULL, contains the size of the rectangle in which the metafile will be displayed. The aspect ratio of the metafile is adjusted to fit this rectangle.
rc (BOOL) - returns
Success indicator.

Returns

rc (BOOL) - returns
Success indicator.
TRUE Successful completion
FALSE Error occurred

Remarks

There is a 3-byte ESC code overhead in the DDF internal buffer for this function. There is also a (MetaFilename length) overhead. Finally, the `prclRect` variable requires an additional 16 bytes of overhead in the DDF internal buffer.

Possible errors include:

  • HMERR_DDF_MEMORY (0x3001) Not enough memory is available.

Example Code

Declaration:

#define INCL_DDF
#include <os2.h>

HDDF      hddf;      /*  Handle to DDF returned by DdfInitialize. */
HMF       hmf;       /*  The handle of the metafile to display. */
PRECTL    prclRect;  /*  Size of the rectangle. */
BOOL      rc;        /*  Success indicator. */

rc = DdfMetafile(hddf, hmf, prclRect);

After initializing a DDF buffer with DdfInitialize and loading a metafile with `GpiLoadMetaFile`, this example uses `DdfMetafile` to place a reference to the metafile in the DDF buffer.

For a more detailed example and discussion of initializing DDF, see the DdfInitialize sample.

#define INCL_WINWINDOWMGR       /* General window management    */
#define INCL_WINMESSAGEMGR      /* Message management           */
#define INCL_DDF                /* Dynamic Data Facility        */
#define INCL_GPIMETAFILES       /* MetaFiles                    */
#include <os2.h>
#include <pmhelp.h>

#define MF_HWND   0
#define ACVP_HAB  4

MRESULT WindowProc(HWND hwnd, ULONG ulMsg, MPARAM mp1, MPARAM mp2)
{
    HWND   hwndParent;
    HAB    hab;
    HWND   hwndInstance;    /* help instance window                 */
    HDDF   hDdf;            /* DDF handle                           */
    HMF    hwndMetaFile;    /* metafile handle                      */

    switch (ulMsg)
    {
    case HM_QUERY_DDF_DATA:
        /* get the help instance */
        hwndParent = WinQueryWindow(hwnd, QW_PARENT);
        hwndParent = WinQueryWindow(hwndParent, QW_PARENT);
        hwndInstance = (HWND)WinSendMsg(hwndParent, HM_QUERY,
                                        MPFROMSHORT(HMQW_INSTANCE), NULL);

        /* Allocate 1K Buffer (default) */
        hDdf = DdfInitialize(
                    hwndInstance,  /* Handle of help instance */
                    0L,            /* Default buffer size     */
                    0L             /* Default increment       */
                    );

        if (hDdf == NULLHANDLE)       /* Check return code */
        {
            return (MRESULT)FALSE;
        }

        /* get hab for this window */
        if ((hab = (HAB)WinQueryWindowULong(hwnd, ACVP_HAB)) == NULLHANDLE)
        {
            return (MRESULT)FALSE;
        }

        /* Load the Metafile to display */
        if ((hwndMetaFile = GpiLoadMetaFile(hab, "SAMP.MET")) == NULLHANDLE)
        {
            return (MRESULT)FALSE;
        }

        /* Save MetaFile hwnd in reserved word */
        WinSetWindowULong(hwnd, MF_HWND, hwndMetaFile);

        if (!DdfMetafile(hDdf, hwndMetaFile, NULL))
        {
            return (MRESULT)FALSE;
        }

        return (MRESULT)hDdf;

    case WM_CLOSE:
        GpiDeleteMetaFile((HMF)WinQueryWindowULong(hwnd, MF_HWND));
        WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));

        return (MRESULT)TRUE;
    }
    return WinDefWindowProc(hwnd, ulMsg, mp1, mp2);
}

Related Functions