/* * Function Name: EnumMetaFile * Program Name: enmetafi.c * SDK Version: 3.0 * Runtime Version: 3.0 * Microsoft C Version: 6.0 * * Description: * This program will enumerate a metafile named * TEST.WMF, playing it record by record. It * will print out the metafile function ID * before each action. * * It is possible to change the mapping mode by * modifying the lines that are commented out in * CALL_EnumMetaFile() to see how the mapping * mode effects the playing of a meta file. * * Copyright (c) 1991 Microsoft Corporation. All rights reserved. */ #include #include "stdio.h" int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int); long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG); BOOL WinInit(HANDLE); void CALL_EnumMetaFile(HDC); BOOL FAR PASCAL EnumProc(HDC, LPHANDLETABLE, LPMETARECORD, int, BYTE FAR *); BOOL bInPaint; HWND hWnd; HANDLE hInst; HWND hWndParent; int xClient, yClient; /*************************************************************************/ BOOL FAR PASCAL EnumProc(hDC, lpHTable, lpMFR, nObj, lpClientData) HDC hDC; LPHANDLETABLE lpHTable; LPMETARECORD lpMFR; int nObj; BYTE FAR * lpClientData; { char szStr[50]; wsprintf(szStr, "Function # 0x%X", lpMFR->rdFunction); MessageBox(hWndParent, szStr, "About to Do", MB_OK); PlayMetaFileRecord(hDC, lpHTable, lpMFR, nObj); return 1; } /***********************************************************************/ void CALL_EnumMetaFile(hDC) HDC hDC; { FARPROC lpprocEnumMF; LOCALHANDLE hMF; // SetMapMode(hDC, MM_ANISOTROPIC); // SetWindowExt(hDC, 10000, 8000); // SetWindowOrg(hDC, 10000, 8000); // SetViewportExt(hDC, xClient, yClient); hMF = GetMetaFile("test.WMF"); if (hMF == 0) { MessageBox(hWndParent, "Can't find TEST.WMF!", "Error", MB_OK); return; } lpprocEnumMF = MakeProcInstance(EnumProc, hInst); EnumMetaFile(hDC, hMF, lpprocEnumMF, (BYTE FAR *) NULL); FreeProcInstance(lpprocEnumMF); hMF = DeleteMetaFile(hMF); return; } /**************************************************************************/ /* Procedure called when the application is loaded for the first time */ BOOL WinInit(hInstance) HANDLE hInstance; { WNDCLASS wcClass; bInPaint = FALSE; wcClass.style = CS_HREDRAW | CS_VREDRAW; wcClass.lpfnWndProc = WndProc; wcClass.cbClsExtra = 0; wcClass.cbWndExtra = 0; wcClass.hInstance = hInstance; wcClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcClass.hCursor = LoadCursor(NULL, IDC_ARROW); wcClass.hbrBackground = GetStockObject(WHITE_BRUSH); wcClass.lpszMenuName = NULL; wcClass.lpszClassName = "EnumMetaFile"; if (!RegisterClass(&wcClass)) /* * Initialization failed. * Windows will automatically deallocate all allocated memory. */ return FALSE; return TRUE; /* Initialization succeeded */ } int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow) HANDLE hInstance, hPrevInstance; LPSTR lpszCmdLine; int cmdShow; { MSG msg; if (!hPrevInstance) { /* Call initialization procedure if this is the first instance */ if (!WinInit(hInstance)) return FALSE; } hWnd = CreateWindow("EnumMetaFile", "EnumMetaFile()", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, /* no parent */ NULL, /* use class menu */ hInstance, /* handle to window instance */ NULL); /* no params to pass on */ hInst = hInstance; /* Make window visible according to the way the app is activated */ ShowWindow(hWnd, cmdShow); UpdateWindow(hWnd); /* Polling messages from event queue */ while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } /* Procedures which make up the window class. */ long FAR PASCAL WndProc(hWnd, message, wParam, lParam) HWND hWnd; unsigned message; WORD wParam; LONG lParam; { PAINTSTRUCT ps; switch (message) { case WM_PAINT: if (bInPaint == TRUE) break; hWndParent = hWnd; bInPaint = TRUE; BeginPaint(hWnd, &ps); CALL_EnumMetaFile(ps.hdc); EndPaint(hWnd, &ps); bInPaint = FALSE; break; case WM_SIZE: xClient = LOWORD(lParam); yClient = HIWORD(lParam); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0L; }