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

  1. /*
  2.  *  
  3.  *  This program demonstrates the use of the function PlayMetaFile.
  4.  *  This function plays the contents of the specified metafile on the
  5.  *  given context.
  6.  *
  7.  */
  8.  
  9. #include <windows.h>
  10. #include "pmetafil.h"
  11.  
  12. static HANDLE hWnd;
  13. static char    szResName [] = "ResMenu";
  14. static char    szFileName[] = "pmetafil";
  15. static char    szFuncName[] = "PlayMetaFile";
  16.  
  17. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  18.  
  19. int    PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  20. HANDLE hInstance, hPrevInstance;
  21. LPSTR  lpszCmdLine;
  22. int    cmdShow;
  23. {
  24.   MSG msg;
  25.   if (!hPrevInstance)
  26.   {
  27.     WNDCLASS rClass;
  28.  
  29.     rClass.lpszClassName = (LPSTR)szFileName;
  30.     rClass.hInstance     = hInstance;
  31.     rClass.lpfnWndProc   = WndProc;
  32.     rClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  33.     rClass.hIcon         = LoadIcon(hInstance, IDI_APPLICATION);
  34.     rClass.lpszMenuName  = NULL;
  35.     rClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  36.     rClass.style         = CS_HREDRAW | CS_VREDRAW;
  37.     rClass.cbClsExtra    = 0;
  38.     rClass.cbWndExtra    = 0;
  39.  
  40.     RegisterClass((LPWNDCLASS) & rClass);
  41.   }
  42.  
  43.   hWnd = CreateWindow((LPSTR)szFileName, (LPSTR)szFuncName,
  44.       WS_OVERLAPPEDWINDOW,
  45.       CW_USEDEFAULT, 0,
  46.       CW_USEDEFAULT, 0,
  47.       NULL, NULL, hInstance, NULL);
  48.  
  49.   ShowWindow(hWnd, cmdShow);
  50.   UpdateWindow (hWnd) ;
  51.  
  52.   while (GetMessage(&msg, NULL, 0, 0))
  53.   {
  54.     TranslateMessage(&msg);
  55.     DispatchMessage(&msg);
  56.   }
  57.   return (msg.wParam) ;
  58. }
  59.  
  60.  
  61. long    FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  62. HWND     hWnd ;
  63. unsigned    iMessage ;
  64. WORD     wParam ;
  65. LONG     lParam ;
  66. {
  67.   static HANDLE hInstance;
  68.   HMENU hMenu;
  69.   HDC hDC;
  70.   HANDLE hMF;
  71.   BOOL bPlayed;
  72.   switch (iMessage)
  73.   {
  74.   case WM_CREATE:
  75.     {
  76.       hInstance = GetWindowWord(hWnd, GWW_HINSTANCE);
  77.       hMenu = LoadMenu(hInstance, "ResMenu");
  78.       SetMenu(hWnd, hMenu);
  79.       DrawMenuBar(hWnd);
  80.       break;
  81.     }
  82.   case WM_COMMAND:
  83.     {
  84.       switch (wParam)
  85.       {
  86.       case IDM_EXECUTE:
  87.     {
  88.       hDC = GetDC(hWnd);
  89.       hMF = GetMetaFile((LPSTR)"PMETAFIL.MET");
  90.  
  91.       MessageBox(GetFocus(), (LPSTR)"About To Play Metafile",
  92.           (LPSTR)szFuncName, MB_OK);
  93.  
  94.       bPlayed = PlayMetaFile(hDC, hMF);
  95.  
  96.       if (bPlayed != 0)
  97.         MessageBox(GetFocus(),
  98.             (LPSTR)"Metafile Played Successfully (Rectangle Generated)",
  99.             (LPSTR)szFuncName, MB_OK);
  100.       else
  101.         MessageBox (GetFocus(), (LPSTR)"Metafile Play Error", (LPSTR)szFuncName,
  102.             MB_OK);
  103.  
  104.       ReleaseDC(hWnd, hDC);
  105.     }
  106.       }
  107.       break;
  108.     }
  109.   case WM_DESTROY:
  110.     {
  111.       PostQuitMessage(0);
  112.       break;
  113.     }
  114.   default:
  115.     {
  116.       return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  117.     }
  118.   }
  119.   return (0L);
  120. }
  121.  
  122.  
  123.