home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Graphics Containers / Nested Graphics Containers / Clipping in Nested Containers / GDITEST67.dpr
Encoding:
Text File  |  2003-10-15  |  3.2 KB  |  119 lines

  1. program GDITEST67;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   GContainer: GraphicsContainer;
  14.   redPen, bluePen : TGPPen;
  15.   aquaBrush, greenBrush : TGPSolidBrush;
  16.   path: TGPGraphicsPath;
  17.   Region: TGPRegion;
  18. begin
  19.   graphics := TGPGraphics.Create(DC);
  20.  
  21.   redPen     := TGPPen.Create(MakeColor(255, 255, 0, 0), 2);
  22.   bluePen    := TGPPen.Create(MakeColor(255, 0, 0, 255), 2);
  23.   aquaBrush  := TGPSolidBrush.Create(MakeColor(255, 180, 255, 255));
  24.   greenBrush := TGPSolidBrush.Create(MakeColor(255, 150, 250, 130));
  25.  
  26.   graphics.SetClip(MakeRect(50, 65, 150, 120));
  27.   graphics.FillRectangle(aquaBrush, 50, 65, 150, 120);
  28.  
  29.   GContainer := graphics.BeginContainer();
  30.      // Create a path that consists of a single ellipse.
  31.      path := TGPGraphicsPath.Create;
  32.      path.AddEllipse(75, 50, 100, 150);
  33.  
  34.     // Construct a region based on the path.
  35.      Region := TGPRegion.Create(path);
  36.      graphics.FillRegion(greenBrush, region);
  37.  
  38.      graphics.SetClip(region);
  39.      graphics.DrawLine(redPen, 50, 0, 350, 300);
  40.   graphics.EndContainer(GContainer);
  41.  
  42.   graphics.DrawLine(bluePen, 70, 0, 370, 300);
  43.  
  44.   redPen.Free;
  45.   bluePen.Free;
  46.   aquaBrush.Free;
  47.   greenBrush.Free;
  48.   path.Free;
  49.   Region.Free;
  50.   graphics.Free;
  51. end;
  52.  
  53.  
  54. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  55. var
  56.   Handle: HDC;
  57.   ps: PAINTSTRUCT;
  58. begin
  59.   case message of
  60.     WM_PAINT:
  61.       begin
  62.         Handle := BeginPaint(Wnd, ps);
  63.         OnPaint(Handle);
  64.         EndPaint(Wnd, ps);
  65.         result := 0;
  66.       end;
  67.  
  68.     WM_DESTROY:
  69.       begin
  70.         PostQuitMessage(0);
  71.         result := 0;
  72.       end;
  73.  
  74.    else
  75.       result := DefWindowProc(Wnd, message, wParam, lParam);
  76.    end;
  77. end;
  78.  
  79. var
  80.   hWnd     : THandle;
  81.   Msg      : TMsg;
  82.   wndClass : TWndClass;
  83. begin
  84.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  85.    wndClass.lpfnWndProc    := @WndProc;
  86.    wndClass.cbClsExtra     := 0;
  87.    wndClass.cbWndExtra     := 0;
  88.    wndClass.hInstance      := hInstance;
  89.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  90.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  91.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  92.    wndClass.lpszMenuName   := nil;
  93.    wndClass.lpszClassName  := 'GettingStarted';
  94.  
  95.    RegisterClass(wndClass);
  96.  
  97.    hWnd := CreateWindow(
  98.       'GettingStarted',       // window class name
  99.       'Clipping in Nested Containers',      // window caption
  100.       WS_OVERLAPPEDWINDOW,    // window style
  101.       Integer(CW_USEDEFAULT), // initial x position
  102.       Integer(CW_USEDEFAULT), // initial y position
  103.       Integer(CW_USEDEFAULT), // initial x size
  104.       Integer(CW_USEDEFAULT), // initial y size
  105.       0,                      // parent window handle
  106.       0,                      // window menu handle
  107.       hInstance,              // program instance handle
  108.       nil);                   // creation parameters
  109.  
  110.    ShowWindow(hWnd, SW_SHOW);
  111.    UpdateWindow(hWnd);
  112.  
  113.    while(GetMessage(msg, 0, 0, 0)) do
  114.    begin
  115.       TranslateMessage(msg);
  116.       DispatchMessage(msg);
  117.    end;
  118. end.
  119.