GdiPlusMetaFile.h 12 KB

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