home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / TEMPLATE / WMF1.C < prev    next >
C/C++ Source or Header  |  1993-12-01  |  7KB  |  280 lines

  1. /*
  2.  * WMF Import Filter - MAIN MODULE
  3.  *
  4.  * LANGUAGE      : Microsoft C6.0
  5.  * MODEL         : medium
  6.  * ENVIRONMENT   : Microsoft Windows 3.0 SDK
  7.  * STATUS        : operational
  8.  *
  9.  * This module defines all the import filter entry points, including
  10.  * the one that initializes the library itself.
  11.  *
  12.  *    Eikon Systems, Inc.
  13.  *    989 East Hillsdale Blvd, Suite 260
  14.  *    Foster City, California 94404
  15.  *    415-349-4664
  16.  *
  17.  * 08/01/91 1.00 - David E. West - initial creation.
  18.  * 09/01/91 1.01 - Kevin P. Welch - minor revisions.
  19.  *
  20.  */
  21.  
  22. #define NOCOMM
  23.  
  24. #include <windows.h>
  25. #include <stdio.h>
  26. #include <dos.h>
  27. #include "wmf.h"
  28.  
  29. /* global variables */
  30. HANDLE        hinstWMF;
  31.  
  32. /* */
  33.  
  34. /*
  35.  * LibMain( hinst, wDataSegment, wHeapSize, lpszCmdLine ) : BOOL;
  36.  *
  37.  *    hinst          handle to dll instance
  38.  *        wDataSegment   current data segment    
  39.  *        cbHeap         desired heap size
  40.  *        lpszCmdLine    long pointer to command line
  41.  *
  42.  * This function is responsible for initializing the WMF import filter
  43.  * library and saving the DLL instance handle.
  44.  *
  45.  * The function always returns TRUE, since initialization never fails.
  46.  *
  47.  */
  48.  
  49. BOOL FAR PASCAL LibMain(
  50.     HANDLE            hinst,
  51.     WORD                wDataSegment,
  52.     WORD                cbHeap,
  53.     LPSTR                lpszCmdLine )
  54. {
  55.     extern HANDLE    hinstWMF;
  56.  
  57.     /* warning level 3 compatibility */
  58.     wDataSegment;
  59.     cbHeap;
  60.     lpszCmdLine;
  61.  
  62.     /* save library instance handle */
  63.     hinstWMF = hinst;
  64.  
  65.     /* return final result */
  66.     return TRUE;
  67. }
  68.  
  69. /* */
  70.  
  71. /*
  72.  * GetFilterInfo( idVersion, lpszIni, lphPrefMem, lphFileTypes ) : WORD
  73.  *
  74.  *    idVersion      source program version number
  75.  *    lpszIni        pointer to optional part of WIN.INI file entry
  76.  *    lphPrefMem     pointer to preferences memory handle
  77.  *    lphFileTypes   pointer to filetypes handle
  78.  *
  79.  * This function returns information about this filter.  It is called once
  80.  * just before the filter is to be used the first time.  The wVersion
  81.  * parameter enables the filter to modify it's behavior depending on the
  82.  * interface.  The preferences memory block may contain information about
  83.  * how the filter should operate.
  84.  *
  85.  * The return value of this function defines the type of import filter
  86.  * this is.  The following types are defined:
  87.  *
  88.  *    0 = error
  89.  *    1 = text filter
  90.  *    2 = graphics filter
  91.  *
  92.  */
  93.  
  94. WORD FAR PASCAL GetFilterInfo( 
  95.     WORD                idVersion,
  96.     LPSTR                lpszIni,
  97.     HANDLE FAR *    lphPrefMem,
  98.     HANDLE FAR *    lphFileTypes )
  99. {
  100.     /* warning level 3 compatibility */
  101.     idVersion;
  102.     lpszIni;
  103.     lphPrefMem;
  104.     lphFileTypes;
  105.  
  106.     /* return graphics filter type */
  107.     return 2;
  108. }
  109.  
  110. /* */
  111.  
  112. /*
  113.  * GetFilterPref( hinst, hwndParent, hPrefMem, wFlags ) : VOID;
  114.  *
  115.  *    hinst          handle to source application instance
  116.  *    hwndParent     parent window for any dialog boxes required
  117.  *    hPrefMem       handle to preferences memory block
  118.  *    wFlags         indicators of PageMaker/PowerPoint context
  119.  *
  120.  * This function can be used by the host application to retrieve
  121.  * and define various filter preferences.  In this instance no
  122.  * action will be performed.
  123.  *
  124.  */
  125.  
  126. VOID FAR PASCAL GetFilterPref( 
  127.     HANDLE            hinst,
  128.     HWND                hwndParent,
  129.     HANDLE            hPrefMem,
  130.     WORD                wFlags )
  131. {
  132.     /* warning level 3 compatibility */
  133.     hinst;
  134.     hwndParent;
  135.     hPrefMem;
  136.     wFlags;
  137. }
  138.  
  139. /* */
  140.  
  141. /*
  142.  * ImportGr( hdcPrint, lpfs, lppi, hPrefMem ) : WORD;
  143.  *
  144.  *    hdcPrint       handle to display context
  145.  *    lpfs           FILESPEC structure for graphics file to import
  146.  *    lppi           PICTINFO structure for metafile created by filter
  147.  *    hPrefMem       handle to preferences memory
  148.  *
  149.  * This function peforms the import of a particular graphics file
  150.  * and generates a metafile.  If an error occurs, the appropriate
  151.  * return code is returned.
  152.  *
  153.  */
  154.  
  155. WORD FAR PASCAL ImportGr(
  156.     HDC             hdcPrint,
  157.     LPFILESPEC      lpfsSrc,
  158.     LPPICTINFO        lppi,
  159.     HANDLE          hPrefMem )
  160. {
  161.     INT                hfSrc;                    /* handle to source file */
  162.     WORD                idErr;                    /* error code to return */
  163.     WORD                cbRead;                    /* bytes read */
  164.     HANDLE            hwmf;                        /* handle to WMF header block */
  165.     HCURSOR            hcsrOld;                    /* handle to old cursor */
  166.     LPWMFHEADER        lpwmf;                    /* long pointer to WMF header */
  167.     OFSTRUCT            ofSrc;                    /* open file structure */
  168.  
  169.     /* for warning level 3 compatibility */
  170.     hPrefMem;
  171.     hdcPrint;
  172.  
  173.     /* initialization */
  174.     idErr = SUCCESS;
  175.  
  176.     /* validate parameters */
  177.     if (lpfsSrc && lppi)
  178.     {
  179.         /* open source WMF file */
  180.         hfSrc = OpenFile( lpfsSrc->fullName, &ofSrc, OF_READ );
  181.         if (hfSrc != -1)
  182.         {
  183.             /* set wait cursor */
  184.             hcsrOld = SetCursor( LoadCursor(NULL,IDC_WAIT) );
  185.             ShowCursor( TRUE );
  186.  
  187.             /* allocate memory for WMF header */
  188.             hwmf = GlobalAlloc( GHND, (LONG)sizeof(WMFHEADER) );
  189.             lpwmf = hwmf ? (LPWMFHEADER)GlobalLock(hwmf) : NULL;
  190.             if (lpwmf)
  191.             {
  192.                 LONG        offEof;                /* end of file */
  193.  
  194.                 /* get end of file */
  195.                 offEof = _llseek( hfSrc, 0L, SEEK_END );
  196.                 _llseek( hfSrc, 0L, SEEK_SET );
  197.  
  198.                 /* read WMF header */
  199.                 cbRead = _lread( hfSrc, (LPSTR)lpwmf, sizeof(WMFHEADER) );
  200.                 if (cbRead == sizeof(WMFHEADER))
  201.                 {
  202.                     /* validate WMF file */
  203.                     if (ValidateWMF(lpwmf))
  204.                     {
  205.                         /* initialize WMF bounding box */
  206.                         CopyRect( &(lppi->bbox), &(lpwmf->bbox) );
  207.                         lppi->inch = lpwmf->cInch;
  208.  
  209.                         /* append WMF bits */
  210.                         idErr = GetWMFBits(
  211.                             &(lppi->hmf),
  212.                             offEof - sizeof(WMFHEADER),
  213.                             hfSrc
  214.                         );
  215.                     }
  216.                     else
  217.                         idErr = IE_NOT_MY_FILE;
  218.                 }
  219.                 else
  220.                     idErr = IE_BAD_FILE_DATA;
  221.  
  222.                 /* unlock WMF header */
  223.                 GlobalUnlock( hwmf );
  224.             }
  225.             else
  226.                 idErr = IE_MEM_FULL;
  227.  
  228.             /* free memory for WMF header */
  229.             if (hwmf)
  230.                 GlobalFree( hwmf );
  231.  
  232.             /* close file */
  233.             _lclose( hfSrc );
  234.  
  235.             /* restore previous cursor*/
  236.             ShowCursor( FALSE );
  237.             SetCursor( hcsrOld );
  238.         }
  239.         else
  240.             idErr = FAILURE;
  241.     }
  242.     else
  243.         idErr = FAILURE;
  244.  
  245.     /* return error code */
  246.     return idErr;
  247. }
  248.  
  249. /* */
  250.  
  251. /*
  252.  * WEP( wValue ) : WORD;
  253.  *
  254.  *        wValue        system exit value
  255.  *
  256.  * This function is called when the DLL is unloaded by the system.
  257.  * It enables the library to perform any cleanup necessary.
  258.  *
  259.  */
  260.  
  261. WORD FAR PASCAL WEP(
  262.     WORD        wValue )
  263. {
  264.     WORD        wResult;
  265.  
  266.     /* process exit value */
  267.     switch( wValue )
  268.         {
  269.     case WEP_FREE_DLL : /* DLL is being released */
  270.     case WEP_SYSTEM_EXIT : /* system is being shut down */
  271.     default :
  272.         wResult = 1;
  273.         break;
  274.     }
  275.  
  276.     /* return result */
  277.     return wResult;
  278.  
  279. }
  280.