home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / metafile / enmetafi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  4.3 KB  |  158 lines

  1. /*
  2.  *  Function Name:   EnumMetaFile
  3.  *  Program Name:    enmetafi.c
  4.  *  SDK Version:         2.03
  5.  *  Runtime Version:     2.03
  6.  *  Microsoft C Version: 5.1
  7.  *
  8.  *  Description:
  9.  *   The program below will create a metafile, close it, then
  10.  *   enumerate it.  The enumeration will play each record in
  11.  *   the metafile.
  12.  */
  13.  
  14. #include "windows.h"
  15.  
  16. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  17.  
  18. HANDLE hInst;
  19.  
  20. /*************************************************************************/
  21.  
  22. BOOL FAR PASCAL EnumProc(hDC, lpHTable, lpMFR, nObj, lpClientData)
  23. HDC      hDC;
  24. LPHANDLETABLE lpHTable;
  25. LPMETARECORD  lpMFR;
  26. int           nObj;
  27. BYTE FAR *    lpClientData;
  28. {
  29.   PlayMetaFileRecord(hDC, lpHTable, lpMFR, nObj);
  30.   return(1);
  31. }
  32.  
  33. /***********************************************************************/
  34.  
  35. void CALL_EnumMetaFile(hDC)
  36. HDC hDC;
  37. {
  38.   FARPROC lpprocEnumMF;
  39.   char szstring[81];
  40.   LOCALHANDLE hMF;
  41.   HDC     hDCMeta;
  42.  
  43.  
  44.   hDCMeta = CreateMetaFile((LPSTR) "enmetafi.met");
  45.   Rectangle (hDCMeta, 10, 10, 400, 200);       /*  metafile records    */
  46.   Rectangle (hDCMeta, 20, 20, 300, 180);       /*  for enumeration count  */
  47.   TextOut (hDCMeta, 40, 40, (LPSTR)"Metafile Enumerated", 19);
  48.  
  49.   hMF = CloseMetaFile (hDCMeta);
  50.  
  51.     lpprocEnumMF = MakeProcInstance ((FARPROC) EnumProc, hInst);
  52.     EnumMetaFile(hDC, hMF, lpprocEnumMF, (BYTE FAR *) NULL);
  53.     FreeProcInstance ((FARPROC) lpprocEnumMF);
  54.  
  55.   return;
  56. }
  57.  
  58. /**************************************************************************/
  59.  
  60. /* Procedure called when the application is loaded for the first time */
  61. BOOL WinInit( hInstance )
  62. HANDLE hInstance;
  63. {
  64.     WNDCLASS   wcClass;
  65.  
  66.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  67.     wcClass.lpfnWndProc    = WndProc;
  68.     wcClass.cbClsExtra     =0;
  69.     wcClass.cbWndExtra     =0;
  70.     wcClass.hInstance      = hInstance;
  71.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  72.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  73.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  74.     wcClass.lpszMenuName   = (LPSTR)NULL;
  75.     wcClass.lpszClassName  = (LPSTR)"EnumMetaFile";
  76.  
  77.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  78.         /* Initialization failed.
  79.          * Windows will automatically deallocate all allocated memory.
  80.          */
  81.         return FALSE;
  82.  
  83.     return TRUE;        /* Initialization succeeded */
  84. }
  85.  
  86.  
  87. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  88. HANDLE hInstance, hPrevInstance;
  89. LPSTR lpszCmdLine;
  90. int cmdShow;
  91. {
  92.     MSG   msg;
  93.     HWND  hWnd;
  94.  
  95.     if (!hPrevInstance)
  96.         {
  97.         /* Call initialization procedure if this is the first instance */
  98.         if (!WinInit( hInstance ))
  99.             return FALSE;
  100.         }
  101.  
  102.     hWnd = CreateWindow((LPSTR)"EnumMetaFile",
  103.                         (LPSTR)"EnumMetaFile()",
  104.                         WS_OVERLAPPEDWINDOW,
  105.                         CW_USEDEFAULT,
  106.                         CW_USEDEFAULT,
  107.                         CW_USEDEFAULT,
  108.                         CW_USEDEFAULT,
  109.                         (HWND)NULL,        /* no parent */
  110.                         (HMENU)NULL,       /* use class menu */
  111.                         (HANDLE)hInstance, /* handle to window instance */
  112.                         (LPSTR)NULL        /* no params to pass on */
  113.                         );
  114.     hInst = hInstance;
  115.  
  116.     /* Make window visible according to the way the app is activated */
  117.     ShowWindow( hWnd, cmdShow );
  118.     UpdateWindow( hWnd );
  119.  
  120.     /* Polling messages from event queue */
  121.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  122.         {
  123.         TranslateMessage((LPMSG)&msg);
  124.         DispatchMessage((LPMSG)&msg);
  125.         }
  126.  
  127.     return (int)msg.wParam;
  128. }
  129.  
  130. /* Procedures which make up the window class. */
  131. long FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  132. HWND hWnd;
  133. unsigned message;
  134. WORD wParam;
  135. LONG lParam;
  136. {
  137.     PAINTSTRUCT ps;
  138.  
  139.     switch (message)
  140.     {
  141.  
  142.     case WM_PAINT:
  143.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  144.         CALL_EnumMetaFile(ps.hdc);
  145.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  146.         break;
  147.  
  148.     case WM_DESTROY:
  149.         PostQuitMessage( 0 );
  150.         break;
  151.  
  152.     default:
  153.         return DefWindowProc( hWnd, message, wParam, lParam );
  154.         break;
  155.     }
  156.     return(0L);
  157. }
  158.