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

  1. /*
  2.  *  Function Name:   DeleteMetaFile
  3.  *  Program Name:    demetafi.c
  4.  *  Special Notes:   Needs CRMETAFI.MET file to run.
  5.  *
  6.  *  SDK Version:         2.03
  7.  *  Runtime Version:     2.03
  8.  *  Microsoft C Version: 5.0
  9.  *
  10.  *  Description:
  11.  *   The program below used to free up memory the metafile has been using.
  12.  *   The metafile may be recalled from the disk into memory by using the
  13.  *   GetMetaFile function.  The program below draws a rectangle, then
  14.  *   releases the metafile handle.
  15.  */
  16.  
  17. #include "windows.h"
  18.  
  19. long    FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  20.  
  21. int    PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  22. HANDLE      hInstance, hPrevInstance;
  23. LPSTR      lpszCmdLine;
  24. int    cmdShow;
  25. {
  26.   MSG         msg;
  27.   HWND         hWnd;
  28.   WNDCLASS   wcClass;
  29.  
  30.   if (!hPrevInstance)
  31.   {
  32.     wcClass.style       = CS_HREDRAW | CS_VREDRAW;
  33.     wcClass.lpfnWndProc    = WndProc;
  34.     wcClass.cbClsExtra       = 0;
  35.     wcClass.cbWndExtra       = 0;
  36.     wcClass.hInstance       = hInstance;
  37.     wcClass.hIcon       = LoadIcon(hInstance, NULL);
  38.     wcClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  39.     wcClass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
  40.     wcClass.lpszMenuName   = (LPSTR)NULL;
  41.     wcClass.lpszClassName  = (LPSTR)"DeleteMetaFile";
  42.  
  43.     if (!RegisterClass((LPWNDCLASS) & wcClass))
  44.       return FALSE;
  45.   }
  46.  
  47.   hWnd = CreateWindow("DeleteMetaFile",
  48.       "DeleteMetaFile()",
  49.       WS_OVERLAPPEDWINDOW,
  50.       CW_USEDEFAULT,
  51.       CW_USEDEFAULT,
  52.       CW_USEDEFAULT,
  53.       CW_USEDEFAULT,
  54.       NULL,
  55.       NULL,
  56.       hInstance,
  57.       NULL);
  58.  
  59.   ShowWindow(hWnd, cmdShow);
  60.   UpdateWindow(hWnd);
  61.   while (GetMessage(&msg, NULL, 0, 0))
  62.   {
  63.     TranslateMessage(&msg);
  64.     DispatchMessage(&msg);
  65.   }
  66.   return msg.wParam;
  67. }
  68.  
  69.  
  70. long    FAR PASCAL WndProc(hWnd, message, wParam, lParam)
  71. HWND       hWnd;
  72. unsigned    message;
  73. WORD       wParam;
  74. LONG       lParam;
  75. {
  76.   PAINTSTRUCT ps;
  77.   HDC          hDC;
  78.   HANDLE      hMetaFile;
  79.  
  80.   switch (message)
  81.   {
  82.   case WM_PAINT:
  83.     {
  84.       BeginPaint(hWnd, &ps);
  85.       hDC = ps.hdc;
  86.       hMetaFile = GetMetaFile("demetafi.met");
  87.       PlayMetaFile(hDC, hMetaFile);
  88.       if (!DeleteMetaFile(hMetaFile))
  89.     MessageBox(hWnd, "DeleteMetaFile failed", "ERROR", MB_ICONHAND);
  90.       else
  91.     TextOut(hDC, 20, 20, "Metafile handle released", 24);
  92.       ValidateRect(hWnd, NULL);
  93.       EndPaint(hWnd, &ps);
  94.       break;
  95.     }
  96.   case WM_DESTROY:
  97.     {
  98.       PostQuitMessage(0);
  99.       break;
  100.     }
  101.   default:
  102.     return DefWindowProc(hWnd, message, wParam, lParam);
  103.   }
  104.   return(0L);
  105. }
  106.  
  107.  
  108.