GdiPlusMetaFile.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:12k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /**************************************************************************
  2. *
  3. * Copyright (c) 1998-2001, Microsoft Corp.  All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. *   GdiplusMetafile.h
  8. *
  9. * Abstract:
  10. *
  11. *   GDI+ Metafile class
  12. *
  13. **************************************************************************/
  14. #ifndef _GDIPLUSMETAFILE_H
  15. #define _GDIPLUSMETAFILE_H
  16. class Metafile : public Image
  17. {
  18. public:
  19.     friend class Image;
  20.     // Playback a metafile from a HMETAFILE
  21.     // If deleteWmf is TRUE, then when the metafile is deleted,
  22.     // the hWmf will also be deleted.  Otherwise, it won't be.
  23.     
  24.     Metafile(IN HMETAFILE                      hWmf,
  25.              IN const WmfPlaceableFileHeader * wmfPlaceableFileHeader,
  26.              IN BOOL                           deleteWmf = FALSE)
  27.     {
  28.         GpMetafile *    metafile = NULL;
  29.         lastResult = DllExports::GdipCreateMetafileFromWmf(hWmf, deleteWmf, 
  30.                                                            wmfPlaceableFileHeader, 
  31.                                                            &metafile);
  32.         SetNativeImage(metafile);
  33.     }
  34.     // Playback a metafile from a HENHMETAFILE
  35.     // If deleteEmf is TRUE, then when the metafile is deleted,
  36.     // the hEmf will also be deleted.  Otherwise, it won't be.
  37.     
  38.     Metafile(IN HENHMETAFILE hEmf,
  39.              IN BOOL deleteEmf = FALSE)
  40.     {
  41.         GpMetafile *    metafile = NULL;
  42.         lastResult = DllExports::GdipCreateMetafileFromEmf(hEmf, deleteEmf, 
  43.                                                            &metafile);
  44.         SetNativeImage(metafile);
  45.     }
  46.     Metafile(IN const WCHAR* filename)
  47.     {
  48.         GpMetafile *    metafile = NULL;
  49.         lastResult = DllExports::GdipCreateMetafileFromFile(filename, 
  50.                                                             &metafile);
  51.         SetNativeImage(metafile);
  52.     }
  53.     // Playback a WMF metafile from a file.
  54.     Metafile(IN const WCHAR*                   filename,
  55.              IN const WmfPlaceableFileHeader * wmfPlaceableFileHeader
  56.             )
  57.     {
  58.         GpMetafile *    metafile = NULL;
  59.         lastResult = DllExports::GdipCreateMetafileFromWmfFile(filename, 
  60.                                                                wmfPlaceableFileHeader, 
  61.                                                                &metafile);
  62.         SetNativeImage(metafile);
  63.     }
  64.     Metafile(IN IStream* stream)
  65.     {
  66.         GpMetafile *    metafile = NULL;
  67.         lastResult = DllExports::GdipCreateMetafileFromStream(stream, 
  68.                                                               &metafile);
  69.         SetNativeImage(metafile);
  70.     }
  71.     // Record a metafile to memory.
  72.     Metafile(
  73.         IN HDC                 referenceHdc,
  74.         IN EmfType             type        = EmfTypeEmfPlusDual,
  75.         IN const WCHAR *       description = NULL
  76.         )
  77.     {
  78.         GpMetafile *    metafile = NULL;
  79.         lastResult = DllExports::GdipRecordMetafile(
  80.                         referenceHdc, type, NULL, MetafileFrameUnitGdi,
  81.                         description, &metafile);
  82.         SetNativeImage(metafile);
  83.     }
  84.     // Record a metafile to memory.
  85.     Metafile(
  86.         IN HDC                 referenceHdc,
  87.         IN const RectF &       frameRect,
  88.         IN MetafileFrameUnit   frameUnit   = MetafileFrameUnitGdi,
  89.         IN EmfType             type        = EmfTypeEmfPlusDual,
  90.         IN const WCHAR *       description = NULL
  91.         )
  92.     {
  93.         GpMetafile *    metafile = NULL;
  94.         lastResult = DllExports::GdipRecordMetafile(
  95.                         referenceHdc, type, &frameRect, frameUnit,
  96.                         description, &metafile);
  97.         SetNativeImage(metafile);
  98.     }
  99.     // Record a metafile to memory.
  100.     Metafile(
  101.         IN HDC                 referenceHdc,
  102.         IN const Rect &        frameRect,
  103.         IN MetafileFrameUnit   frameUnit   = MetafileFrameUnitGdi,
  104.         IN EmfType             type        = EmfTypeEmfPlusDual,
  105.         IN const WCHAR *       description = NULL
  106.         )
  107.     {
  108.         GpMetafile *    metafile = NULL;
  109.         lastResult = DllExports::GdipRecordMetafileI(
  110.                         referenceHdc, type, &frameRect, frameUnit,
  111.                         description, &metafile);
  112.         SetNativeImage(metafile);
  113.     }
  114.     Metafile(
  115.         IN const WCHAR*        fileName,
  116.         IN HDC                 referenceHdc,
  117.         IN EmfType             type        = EmfTypeEmfPlusDual,
  118.         IN const WCHAR *       description = NULL
  119.         )
  120.     {
  121.         GpMetafile *    metafile = NULL;
  122.         lastResult = DllExports::GdipRecordMetafileFileName(fileName,
  123.                         referenceHdc, type, NULL, MetafileFrameUnitGdi,
  124.                         description, &metafile);
  125.         SetNativeImage(metafile);
  126.     }
  127.     Metafile(
  128.         IN const WCHAR*        fileName,
  129.         IN HDC                 referenceHdc,
  130.         IN const RectF &       frameRect,
  131.         IN MetafileFrameUnit   frameUnit   = MetafileFrameUnitGdi,
  132.         IN EmfType             type        = EmfTypeEmfPlusDual,
  133.         IN const WCHAR *       description = NULL
  134.         )
  135.     {
  136.         GpMetafile *    metafile = NULL;
  137.         lastResult = DllExports::GdipRecordMetafileFileName(fileName,
  138.                         referenceHdc, type, &frameRect, frameUnit,
  139.                         description, &metafile);
  140.         SetNativeImage(metafile);
  141.     }
  142.     Metafile(
  143.         IN const WCHAR*        fileName,
  144.         IN HDC                 referenceHdc,
  145.         IN const Rect &        frameRect,
  146.         IN MetafileFrameUnit   frameUnit   = MetafileFrameUnitGdi,
  147.         IN EmfType             type        = EmfTypeEmfPlusDual,
  148.         IN const WCHAR *       description = NULL
  149.         )
  150.     {
  151.         GpMetafile *    metafile = NULL;
  152.         lastResult = DllExports::GdipRecordMetafileFileNameI(fileName,
  153.                         referenceHdc, type, &frameRect, frameUnit,
  154.                         description, &metafile);
  155.         SetNativeImage(metafile);
  156.     }
  157.     Metafile(
  158.         IN IStream *           stream,
  159.         IN HDC                 referenceHdc,
  160.         IN EmfType             type        = EmfTypeEmfPlusDual,
  161.         IN const WCHAR *       description = NULL
  162.         )
  163.     {
  164.         GpMetafile *    metafile = NULL;
  165.         lastResult = DllExports::GdipRecordMetafileStream(stream,
  166.                         referenceHdc, type, NULL, MetafileFrameUnitGdi,
  167.                         description, &metafile);
  168.         SetNativeImage(metafile);
  169.     }
  170.     Metafile(
  171.         IN IStream *           stream,
  172.         IN HDC                 referenceHdc,
  173.         IN const RectF &       frameRect,
  174.         IN MetafileFrameUnit   frameUnit   = MetafileFrameUnitGdi,
  175.         IN EmfType             type        = EmfTypeEmfPlusDual,
  176.         IN const WCHAR *       description = NULL
  177.         )
  178.     {
  179.         GpMetafile *    metafile = NULL;
  180.         lastResult = DllExports::GdipRecordMetafileStream(stream,
  181.                         referenceHdc, type, &frameRect, frameUnit,
  182.                         description, &metafile);
  183.         SetNativeImage(metafile);
  184.     }
  185.     Metafile(
  186.         IN IStream *           stream,
  187.         IN HDC                 referenceHdc,
  188.         IN const Rect &        frameRect,
  189.         IN MetafileFrameUnit   frameUnit   = MetafileFrameUnitGdi,
  190.         IN EmfType             type        = EmfTypeEmfPlusDual,
  191.         IN const WCHAR *       description = NULL
  192.         )
  193.     {
  194.         GpMetafile *    metafile = NULL;
  195.         lastResult = DllExports::GdipRecordMetafileStreamI(stream,
  196.                         referenceHdc, type, &frameRect, frameUnit,
  197.                         description, &metafile);
  198.         SetNativeImage(metafile);
  199.     }
  200.     static Status GetMetafileHeader(
  201.         IN HMETAFILE                       hWmf,
  202.         IN const WmfPlaceableFileHeader *  wmfPlaceableFileHeader,
  203.         OUT MetafileHeader *               header
  204.         )
  205.     {
  206.         return DllExports::GdipGetMetafileHeaderFromWmf(hWmf,
  207.                                                         wmfPlaceableFileHeader, 
  208.                                                         header);
  209.     }
  210.     static Status GetMetafileHeader(
  211.         IN HENHMETAFILE        hEmf,
  212.         OUT MetafileHeader *   header
  213.         )
  214.     {
  215.         return DllExports::GdipGetMetafileHeaderFromEmf(hEmf, header);
  216.     }
  217.     static Status GetMetafileHeader(
  218.         IN const WCHAR*        filename,
  219.         OUT MetafileHeader *   header
  220.         )
  221.     {
  222.         return DllExports::GdipGetMetafileHeaderFromFile(filename, header);
  223.     }
  224.     static Status GetMetafileHeader(
  225.         IN IStream *           stream,
  226.         OUT MetafileHeader *   header
  227.         )
  228.     {
  229.         return DllExports::GdipGetMetafileHeaderFromStream(stream, header);
  230.     }
  231.     Status GetMetafileHeader(
  232.         OUT MetafileHeader *    header
  233.         ) const
  234.     {
  235.         return SetStatus(DllExports::GdipGetMetafileHeaderFromMetafile(
  236.                                               (GpMetafile *)nativeImage,
  237.                                               header));
  238.     }
  239.     // Once this method is called, the Metafile object is in an invalid state
  240.     // and can no longer be used.  It is the responsiblity of the caller to
  241.     // invoke DeleteEnhMetaFile to delete this hEmf.
  242.     HENHMETAFILE GetHENHMETAFILE()
  243.     {
  244.         HENHMETAFILE hEmf;
  245.         SetStatus(DllExports::GdipGetHemfFromMetafile(
  246.                                   (GpMetafile *)nativeImage, 
  247.                                   &hEmf));
  248.         return hEmf;
  249.     }
  250.     // Used in conjuction with Graphics::EnumerateMetafile to play an EMF+
  251.     // The data must be DWORD aligned if it's an EMF or EMF+.  It must be
  252.     // WORD aligned if it's a WMF.
  253.     
  254.     Status PlayRecord(
  255.         IN EmfPlusRecordType   recordType,
  256.         IN UINT                flags,
  257.         IN UINT                dataSize,
  258.         IN const BYTE *        data
  259.         ) const
  260.     {
  261.         return SetStatus(DllExports::GdipPlayMetafileRecord(
  262.                                 (GpMetafile *)nativeImage,
  263.                                 recordType,
  264.                                 flags,
  265.                                 dataSize,
  266.                                 data));
  267.     }
  268.     // If you're using a printer HDC for the metafile, but you want the
  269.     // metafile rasterized at screen resolution, then use this API to set
  270.     // the rasterization dpi of the metafile to the screen resolution,
  271.     // e.g. 96 dpi or 120 dpi.
  272.     
  273.     Status SetDownLevelRasterizationLimit(
  274.         IN UINT     metafileRasterizationLimitDpi
  275.         )
  276.     {
  277.         return SetStatus(DllExports::
  278.                          GdipSetMetafileDownLevelRasterizationLimit(
  279.                                 (GpMetafile *)nativeImage,
  280.                                 metafileRasterizationLimitDpi));
  281.     }
  282.     UINT GetDownLevelRasterizationLimit() const
  283.     {
  284.         UINT    metafileRasterizationLimitDpi = 0;
  285.         SetStatus(DllExports::GdipGetMetafileDownLevelRasterizationLimit(
  286.                                 (GpMetafile *)nativeImage,
  287.                                 &metafileRasterizationLimitDpi));
  288.         return metafileRasterizationLimitDpi;
  289.     }
  290.     static UINT Metafile::EmfToWmfBits(
  291.         IN HENHMETAFILE       hemf,
  292.         IN UINT               cbData16,
  293.         IN LPBYTE             pData16,
  294.         IN INT                iMapMode = MM_ANISOTROPIC,
  295.         IN EmfToWmfBitsFlags  eFlags = EmfToWmfBitsFlagsDefault
  296.     )
  297.     {
  298.         return DllExports::GdipEmfToWmfBits(
  299.             hemf,
  300.             cbData16,
  301.             pData16,
  302.             iMapMode,
  303.             eFlags);
  304.     }
  305. protected:
  306.     Metafile()
  307.     {
  308.         SetNativeImage(NULL);
  309.         lastResult = Ok;
  310.     }
  311. private:
  312.     Metafile(const Metafile &);
  313.     Metafile& operator=(const Metafile &);
  314. };
  315. #endif // !_METAFILE_H