Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

367 lines
10 KiB

  1. #include "resource.h"
  2. #include "commdlg.h"
  3. #define GlobalSizePtr(lp) \
  4. (GlobalUnlockPtr(lp), (BOOL)GlobalSize(GlobalPtrHandle(lp)))
  5. #define APPNAME "Metafile Decoder"
  6. #define DESTDISPLAY 0
  7. #define DESTMETA 1
  8. #define DESTDIB 2
  9. #define DESTPRN 3
  10. extern int iDestDC;
  11. //
  12. //common dialog structures and constants
  13. //
  14. #define MAXFILTERLEN 256
  15. typedef struct tagFOCHUNK {
  16. OPENFILENAME of;
  17. char szFile[256];
  18. char szFileTitle[256];
  19. } FOCHUNK;
  20. typedef FOCHUNK FAR *LPFOCHUNK;
  21. typedef FOCHUNK FAR *LPFSCHUNK;
  22. typedef WORD (CALLBACK* FARHOOK)(HWND,UINT,WPARAM,LPARAM);
  23. //
  24. //structure of ptrs to global memory for emf header and
  25. //description string
  26. //
  27. typedef struct tagEHNMETAMEMPTR {
  28. LPENHMETAHEADER lpEMFHdr;
  29. LPTSTR lpDescStr;
  30. LPPALETTEENTRY lpPal;
  31. WORD palNumEntries;
  32. } EHNMETAMEMPTR, *PEHNMETAMEMPTR, *LPEHNMETAMEMPTR;
  33. //
  34. //clipboard data definitions
  35. //
  36. #define CLP_ID 0xC350
  37. #define CLP_NT_ID 0xC351
  38. #define CLPBK_NT_ID 0xC352
  39. #define CLPMETANAMEMAX 79
  40. //
  41. //NT clipboard file header
  42. //
  43. typedef struct {
  44. WORD FileIdentifier;
  45. WORD FormatCount;
  46. } NTCLIPFILEHEADER;
  47. //
  48. // NT clipboard file format header
  49. //
  50. typedef struct {
  51. DWORD FormatID;
  52. DWORD DataLen;
  53. DWORD DataOffset;
  54. WCHAR Name[CLPMETANAMEMAX];
  55. } NTCLIPFILEFORMAT, *LPNTCLIPFILEFORMAT;
  56. //
  57. //Win 3.1 clipboard file header
  58. //
  59. #pragma pack(1)
  60. typedef struct {
  61. WORD FileIdentifier;
  62. WORD FormatCount;
  63. } CLIPFILEHEADER;
  64. //
  65. //Win 3.1 clipboard format header
  66. //
  67. typedef struct {
  68. WORD FormatID;
  69. DWORD DataLen;
  70. DWORD DataOffset;
  71. char Name[CLPMETANAMEMAX];
  72. } CLIPFILEFORMAT, FAR *LPCLIPFILEFORMAT;
  73. //
  74. //Win 3.1 metafilepict structure
  75. //
  76. typedef struct tagOLDMETAFILEPICT {
  77. short mm;
  78. short xExt;
  79. short yExt;
  80. WORD hMF;
  81. } OLDMETAFILEPICT;
  82. typedef OLDMETAFILEPICT FAR *LPOLDMETAFILEPICT;
  83. //
  84. //placeable metafile data definitions
  85. //
  86. typedef struct tagOLDRECT
  87. {
  88. short left;
  89. short top;
  90. short right;
  91. short bottom;
  92. } OLDRECT;
  93. //
  94. //placeable metafile header
  95. //
  96. typedef struct {
  97. DWORD key;
  98. WORD hmf;
  99. OLDRECT bbox;
  100. WORD inch;
  101. DWORD reserved;
  102. WORD checksum;
  103. }PLACEABLEWMFHEADER;
  104. #pragma pack()
  105. #define PLACEABLEKEY 0x9AC6CDD7
  106. //
  107. //metafile function table lookup data definitions
  108. //
  109. #define NUMENHMETARECORDS 255 // includes WFM, EMF, EMF+
  110. typedef struct tagEMFMETARECORDS {
  111. char *szRecordName;
  112. DWORD iType;
  113. } EMFMETARECORDS, *LPEMFMETARECORDS;
  114. #define NUMMETAFUNCTIONS 79 // WMF record types
  115. /*
  116. typedef struct tagMETAFUNCTIONS {
  117. char *szFuncName;
  118. WORD value;
  119. } METAFUNCTIONS;
  120. */
  121. typedef LPWORD LPPARAMETERS;
  122. typedef LPDWORD LPEMFPARAMETERS;
  123. //
  124. //global vars for main module
  125. //
  126. #ifdef MAIN
  127. HANDLE hInst;
  128. HANDLE CurrenthDlg;
  129. HANDLE hSaveCursor;
  130. HWND hWndMain;
  131. HWND hWndList;
  132. LPPARAMETERS lpMFParams;
  133. LPEMFPARAMETERS lpEMFParams;
  134. HANDLE hMem;
  135. HANDLE hSelMem;
  136. int FAR *lpSelMem;
  137. EHNMETAMEMPTR EmfPtr;
  138. //
  139. //flags
  140. //
  141. BOOL bInPaint;
  142. BOOL bPlayRec;
  143. BOOL bPlayItAll;
  144. BOOL bBadFile = FALSE;
  145. BOOL bValidFile = FALSE;
  146. BOOL bEnhMeta = FALSE;
  147. BOOL bMetaFileOpen = FALSE;
  148. BOOL bMetaInRam = FALSE;
  149. BOOL bPlaceableMeta= FALSE;
  150. BOOL bPlayList = FALSE;
  151. BOOL bPlaySelList = TRUE;
  152. BOOL bEnumRange;
  153. int iEnumAction;
  154. int iStartRange;
  155. int iEndRange;
  156. DWORD iCount = 0; //index into lpSelMem
  157. DWORD iNumSel = 0; //number of listbox selections
  158. //
  159. //common fo dialog vars
  160. //
  161. char gszSaveEMFFilter[MAXFILTERLEN]="Enhanced MetaFile(*.EMF)\0*.EMF\0\0";
  162. char gszSaveWMFFilter[MAXFILTERLEN]="Windows MetaFile(*.WMF)\0*.WMF\0\0";
  163. char gszFilter[MAXFILTERLEN]="All Supported File Types(*.EMF,*.WMF,*.CLP)\0*.EMF;*.WMF;*.CLP\0Enhanced MetaFiles(*.EMF)\0*.EMF\0Windows Metafiles(*.WMF)\0*.WMF\0Clipboard Pictures(*.CLP)\0*.CLP\0\0";
  164. char gszBuffer[MAXFILTERLEN];
  165. int nFileOffset;
  166. int nExtOffset;
  167. //
  168. //file io related vars
  169. //
  170. char OpenName[144];
  171. char SaveName[144];
  172. char str[255];
  173. OFSTRUCT ofStruct;
  174. DWORD iLBItemsInBuf;
  175. char fnameext[20];
  176. //
  177. //metafile related vars
  178. //
  179. HANDLE hMF;
  180. HENHMETAFILE hemf;
  181. METAFILEPICT MFP;
  182. METARECORD MetaRec;
  183. METAHEADER mfHeader;
  184. PLACEABLEWMFHEADER placeableWMFHeader;
  185. ENHMETAHEADER emfHeader;
  186. ENHMETARECORD emfMetaRec;
  187. DWORD iRecNum = 0;
  188. HANDLE hMFP;
  189. LPMETAFILEPICT lpMFP = NULL;
  190. LPOLDMETAFILEPICT lpOldMFP = NULL;
  191. HGLOBAL hMFBits;
  192. LPSTR lpMFBits = NULL;
  193. //
  194. //printer variables
  195. //
  196. HDC hPr; // handle for printer device context
  197. POINT PhysPageSize; // information about the page
  198. BOOL bAbort; // FALSE if user cancels printing
  199. HWND hAbortDlgWnd;
  200. FARPROC lpAbortDlg;
  201. FARPROC lpAbortProc;
  202. #endif /* if defined MAIN */
  203. //
  204. //externs
  205. //
  206. #ifndef MAIN
  207. extern HANDLE hInst;
  208. extern HANDLE CurrenthDlg;
  209. extern HANDLE hSaveCursor;
  210. extern HWND hWndMain;
  211. extern HWND hWndList;
  212. extern LPPARAMETERS lpMFParams;
  213. extern LPEMFPARAMETERS lpEMFParams;
  214. extern HANDLE hMem;
  215. extern HANDLE hSelMem;
  216. extern int FAR *lpSelMem;
  217. extern EHNMETAMEMPTR EmfPtr;
  218. //
  219. //flags
  220. //
  221. extern BOOL bInPaint;
  222. extern BOOL bPlayRec;
  223. extern BOOL bPlayItAll;
  224. extern BOOL bBadFile;
  225. extern BOOL bValidFile;
  226. extern BOOL bEnhMeta;
  227. extern BOOL bMetaFileOpen;
  228. extern BOOL bMetaInRam;
  229. extern BOOL bPlaceableMeta;
  230. extern BOOL bPlayList;
  231. extern BOOL bPlaySelList;
  232. extern BOOL bEnumRange;
  233. extern int iEnumAction;
  234. extern int iStartRange;
  235. extern int iEndRange;
  236. extern DWORD iCount; //index into lpSelMem
  237. extern DWORD iNumSel; //number of listbox selections
  238. //
  239. //common dialog vars
  240. //
  241. extern char gszSaveEMFFilter[MAXFILTERLEN];
  242. extern char gszSaveWMFFilter[MAXFILTERLEN];
  243. extern char gszFilter[MAXFILTERLEN];
  244. extern char gszBuffer[MAXFILTERLEN];
  245. extern int nFileOffset;
  246. extern int nExtOffset;
  247. //
  248. //file io related vars
  249. //
  250. extern char OpenName[144];
  251. extern char SaveName[144];
  252. extern char str[256];
  253. extern OFSTRUCT ofStruct;
  254. extern DWORD iLBItemsInBuf;
  255. extern char fnameext[20];
  256. //
  257. //metafile related vars
  258. //
  259. extern HANDLE hMF;
  260. extern HENHMETAFILE hemf;
  261. extern METAFILEPICT MFP;
  262. extern METARECORD MetaRec;
  263. extern METAHEADER mfHeader;
  264. extern PLACEABLEWMFHEADER placeableWMFHeader;
  265. extern ENHMETAHEADER emfHeader;
  266. extern ENHMETARECORD emfMetaRec;
  267. extern DWORD iRecNum;
  268. extern EMFMETARECORDS emfMetaRecords[];
  269. // extern METAFUNCTIONS MetaFunctions[];
  270. extern HANDLE hMFP;
  271. extern LPMETAFILEPICT lpMFP;
  272. extern LPOLDMETAFILEPICT lpOldMFP;
  273. extern HGLOBAL hMFBits;
  274. extern LPSTR lpMFBits;
  275. //
  276. //printer variables
  277. //
  278. extern HDC hPr; // handle for printer device context
  279. extern POINT PhysPageSize; // information about the page
  280. extern BOOL bAbort; // FALSE if user cancels printing
  281. extern HWND hAbortDlgWnd;
  282. #endif /* if !defined MAIN */
  283. //
  284. //function prototypes
  285. //
  286. //
  287. //MFDCOD32.C
  288. int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
  289. BOOL InitApplication(HANDLE);
  290. BOOL InitInstance(HANDLE, int);
  291. LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
  292. HANDLE FAR PASCAL OpenDlg(HWND, unsigned, WORD, LONG);
  293. void WaitCursor(BOOL);
  294. //
  295. //WMFMETA.C
  296. //
  297. int CALLBACK EnhMetaFileEnumProc(HDC, LPHANDLETABLE, LPENHMETARECORD, int, LPARAM);
  298. int CALLBACK MetaEnumProc(HDC, LPHANDLETABLE, LPMETARECORD, int, LPARAM);
  299. BOOL LoadParameterLB(HWND, DWORD, int);
  300. BOOL PlayMetaFileToDest(HWND, int);
  301. BOOL RenderClipMeta(LPVOID, int, WORD);
  302. BOOL RenderPlaceableMeta(int);
  303. void SetPlaceableExts(HDC, PLACEABLEWMFHEADER, int);
  304. void SetNonPlaceableExts(HDC, int);
  305. VOID SetClipMetaExts(HDC, LPMETAFILEPICT, LPOLDMETAFILEPICT, int);
  306. BOOL ProcessFile(HWND, LPSTR);
  307. BOOL ProcessWMF(HWND hWnd, LPSTR lpFileName);
  308. BOOL ProcessCLP(HWND hWnd, LPSTR lpFileName);
  309. BOOL ProcessEMF(HWND hWnd, LPSTR lpFileName);
  310. BOOL GetEMFCoolStuff(void);
  311. BOOL GetEMFCoolStuff(void);
  312. int EnumMFIndirect(HDC hDC, LPHANDLETABLE lpHTable,
  313. LPMETARECORD lpMFR,
  314. LPENHMETARECORD lpEMFR,
  315. int nObj, LPARAM lpData);
  316. BOOL ConvertWMFtoEMF(HMETAFILE hmf, LPSTR lpszFileName);
  317. BOOL ConvertEMFtoWMF(HDC hrefDC, HENHMETAFILE hEMF, LPSTR lpszFileName);
  318. //
  319. //DLGPROC.C
  320. //
  321. INT_PTR CALLBACK WMFRecDlgProc(HWND, unsigned, WPARAM, LPARAM);
  322. INT_PTR CALLBACK EnhMetaHeaderDlgProc(HWND, unsigned, WPARAM, LPARAM);
  323. INT_PTR CALLBACK HeaderDlgProc(HWND, unsigned, WPARAM, LPARAM);
  324. INT_PTR CALLBACK ClpHeaderDlgProc(HWND, unsigned, WPARAM, LPARAM);
  325. INT_PTR CALLBACK PlaceableHeaderDlgProc(HWND, unsigned, WPARAM, LPARAM);
  326. INT_PTR CALLBACK EnumRangeDlgProc(HWND, unsigned, WPARAM, LPARAM);
  327. INT_PTR CALLBACK ListDlgProc(HWND, unsigned, WPARAM, LPARAM);
  328. INT_PTR CALLBACK PlayFromListDlgProc(HWND, unsigned, WPARAM, LPARAM);
  329. INT_PTR CALLBACK About(HWND, unsigned, WPARAM, LPARAM);
  330. //
  331. //WMFPRINT.C
  332. //
  333. BOOL PrintWMF(BOOL);
  334. HANDLE GetPrinterDC(BOOL);
  335. INT_PTR CALLBACK AbortDlg(HWND, unsigned, WPARAM, LPARAM);
  336. BOOL CALLBACK AbortProc(HDC, int);
  337. //
  338. //CMNDLG.C
  339. //
  340. void InitializeStruct(WORD, LPSTR, LPSTR);
  341. int OpenFileDialog(LPSTR);
  342. int SaveFileDialog(LPSTR, LPSTR);
  343. void SplitPath( LPSTR, LPSTR, LPSTR, LPSTR, LPSTR);