Creating and Drawing into a Metafile

To create a metafile, you must:

The following figure shows how to create a simple metafile that draws text within the borders of a three-color box.

#include <os2.h>void fncMETA01(void){
    DEVOPENSTRUC dop;
    HDC hdcMeta;
    HPS hpsMeta;
    HMF hmf;
    HAB hab;
    SIZEL sizlPage;
    POINTL ptl;

    dop.pszLogAddress = (PSZ) NULL;
    dop.pszDriverName = "DISPLAY";

    hdcMeta = DevOpenDC(hab,
        OD_METAFILE,                 /* Metafile device context             */
        "*",                         /* Ignores OS2.INI                     */
        2L,                          /* Uses first two fields               */
        (PDEVOPENDATA) &dop,         /* Device information                  */
        (HDC) NULLHANDLE);           /* Compatible device context           */

    hpsMeta = GpiCreatePS(hab,
        hdcMeta,                     /* Metafile device context             */
        &sizlPage,                   /* Page viewport                       */
        PU_PELS | GPIA_ASSOC);       /* Device units and associated context */

    /* Draw a box in a metafile. */

    GpiSetColor(hpsMeta, CLR_CYAN);

    ptl.x = 150; ptl.y = 200;
    GpiMove(hpsMeta, &ptl);


    ptl.x = 300; ptl.y = 275;
    GpiBox(hpsMeta, DRO_FILL, &ptl, 0L, 0L);

    GpiSetColor(hpsMeta, CLR_GREEN);

    ptl.x = 300; ptl.y = 200;
    GpiMove(hpsMeta, &ptl);

    ptl.x = 390; ptl.y = 275;
    GpiBox(hpsMeta, DRO_FILL, &ptl, 0L, 0L);


    GpiSetColor(hpsMeta, CLR_YELLOW);

    ptl.x = 390; ptl.y = 200;
    GpiMove(hpsMeta, &ptl);

    ptl.x = 530; ptl.y = 275;
    GpiBox(hpsMeta, DRO_FILL, &ptl, 0L, 0L);

    ptl.x = 175; ptl.y = 230;
    GpiMove(hpsMeta, &ptl);


    GpiSetColor(hpsMeta, CLR_PINK);

    GpiCharString(hpsMeta, 41,
        "METAFILE COPY METAFILE COPY METAFILE COPY");

    GpiAssociate(hpsMeta, (HDC) NULLHANDLE);
    hmf = DevCloseDC(hdcMeta);
} /* fncMETA01 */

Creating a Metafile


[Back: Using Metafiles]
[Next: Drawing into a Metafile in Retain Mode]