home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Special / EnumerateMetafile / GDITEST16.dpr
Encoding:
Text File  |  2003-10-15  |  3.5 KB  |  123 lines

  1. program GDITEST16;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. function metaCallback(recordType  : TEmfPlusRecordType;
  11.                        flags       : UINT;
  12.                        dataSize    : UINT;
  13.                        data        : PBYTE;
  14.                        callbackData: pointer
  15.                        ): BOOL; stdcall;
  16. begin
  17.    // Play only EmfPlusRecordTypeFillEllipse records.
  18.    if (recordType = EmfPlusRecordTypeFillEllipse) then
  19.    begin
  20.    // Explicitly cast callbackData as a metafile pointer, and use it to call
  21.    // the PlayRecord method.
  22.      TGPMetafile(callbackData).PlayRecord(recordType, flags, dataSize, Data);
  23.    end;
  24.    result := TRUE;
  25. end;
  26.  
  27.  
  28. Procedure OnPaint(DC: HDC);
  29. var
  30.   graphics : TGPGraphics;
  31.   pMeta: TGPMetafile;
  32.   metaGraphics: TGPGraphics;
  33.   blackBrush: TGPSolidBrush;
  34.   redBrush: TGPSolidBrush;
  35. begin
  36.   graphics := TGPGraphics.Create(DC);
  37.   // Create a Metafile object from an existing disk metafile.
  38.   pMeta := TGPMetaFile.Create('..\..\Media\SampleMetafile.emf');
  39.     // Fill a rectangle and an ellipse in pMeta.
  40.     metaGraphics := TGPGraphics.Create(pMeta);
  41.     blackBrush:= TGPSolidBrush.Create(MakeColor(255, 0, 0, 0));
  42.     redBrush:= TGPSolidBrush.Create(MakeColor(255, 255, 0, 0));
  43.     metaGraphics.FillRectangle(blackBrush, 0, 0, 100, 100);
  44.     metaGraphics.FillEllipse(redBrush, 100, 0, 200, 100);
  45.  
  46.   // Enumerate pMeta, passing pMeta as the callback data.
  47.   graphics.EnumerateMetafile(pMeta, MakePoint(0, 0), metaCallback, pMeta);
  48.   graphics.DrawImage(pMeta, MakePoint(0, 150));
  49.  
  50.   pMeta.free;
  51.   metaGraphics.free;
  52.   blackBrush.free;
  53.   redBrush.free;
  54.   graphics.Free;
  55. end;
  56.  
  57.  
  58. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  59. var
  60.   Handle: HDC;
  61.   ps: PAINTSTRUCT;
  62. begin
  63.   case message of
  64.     WM_PAINT:
  65.       begin
  66.         Handle := BeginPaint(Wnd, ps);
  67.         OnPaint(Handle);
  68.         EndPaint(Wnd, ps);
  69.         result := 0;
  70.       end;
  71.  
  72.     WM_DESTROY:
  73.       begin
  74.         PostQuitMessage(0);
  75.         result := 0;
  76.       end;
  77.  
  78.    else
  79.       result := DefWindowProc(Wnd, message, wParam, lParam);
  80.    end;
  81. end;
  82.  
  83. var
  84.   hWnd     : THandle;
  85.   Msg      : TMsg;
  86.   wndClass : TWndClass;
  87. begin
  88.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  89.    wndClass.lpfnWndProc    := @WndProc;
  90.    wndClass.cbClsExtra     := 0;
  91.    wndClass.cbWndExtra     := 0;
  92.    wndClass.hInstance      := hInstance;
  93.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  94.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  95.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  96.    wndClass.lpszMenuName   := nil;
  97.    wndClass.lpszClassName  := 'GettingStarted';
  98.  
  99.    RegisterClass(wndClass);
  100.  
  101.    hWnd := CreateWindow(
  102.       'GettingStarted',       // window class name
  103.       'EnumerateMetafile',       // window caption
  104.       WS_OVERLAPPEDWINDOW,    // window style
  105.       Integer(CW_USEDEFAULT), // initial x position
  106.       Integer(CW_USEDEFAULT), // initial y position
  107.       Integer(CW_USEDEFAULT), // initial x size
  108.       Integer(CW_USEDEFAULT), // initial y size
  109.       0,                      // parent window handle
  110.       0,                      // window menu handle
  111.       hInstance,              // program instance handle
  112.       nil);                   // creation parameters
  113.  
  114.    ShowWindow(hWnd, SW_SHOW);
  115.    UpdateWindow(hWnd);
  116.  
  117.    while(GetMessage(msg, 0, 0, 0)) do
  118.    begin
  119.       TranslateMessage(msg);
  120.       DispatchMessage(msg);
  121.    end;
  122. end.
  123.