program GDITEST80;

uses
  Windows,
  Messages,
  SysUtils,
  GDIPAPI,
  GDIPOBJ;


Procedure OnPaint(DC: HDC);
var
  graphics : TGPGraphics;
  points: array[0..2] of TGPPoint;
  pthGrBrush: TGPPathGradientBrush;
const
  presetColors: array[0..2] of TGPColor = (aclGreen, aclAqua, aclBlue);
  interpPositions: array[0..2] of Single = (0.0, 0.25, 1.0);
begin
  graphics := TGPGraphics.Create(DC);

  // Vertices of the triangle
  points[0] := MakePoint(100, 0);
  points[1] := MakePoint(200, 200);
  points[2] := MakePoint(0, 200);

  // No GraphicsPath object is created. The PathGradient
  // brush is constructed directly from the array of points.
  pthGrBrush:= TGPPathGradientBrush.Create(PGPPoint(@points), 3);

  pthGrBrush.SetInterpolationColors(@presetColors, @interpPositions, 3);

  // Fill a rectangle that is larger than the triangle
  // specified in the Point array. The portion of the
  // rectangle outside the triangle will not be painted.
  graphics.FillRectangle(pthGrBrush, 0, 0, 200, 200);

  pthGrBrush.Free;
  graphics.Free;
end;


function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
var
  Handle: HDC;
  ps: PAINTSTRUCT;
begin
  case message of
    WM_PAINT:
      begin
        Handle := BeginPaint(Wnd, ps);
        OnPaint(Handle);
        EndPaint(Wnd, ps);
        result := 0;
      end;

    WM_DESTROY:
      begin
        PostQuitMessage(0);
        result := 0;
      end;

   else
      result := DefWindowProc(Wnd, message, wParam, lParam);
   end;
end;

var
  hWnd     : THandle;
  Msg      : TMsg;
  wndClass : TWndClass;
begin
   wndClass.style          := CS_HREDRAW or CS_VREDRAW;
   wndClass.lpfnWndProc    := @WndProc;
   wndClass.cbClsExtra     := 0;
   wndClass.cbWndExtra     := 0;
   wndClass.hInstance      := hInstance;
   wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
   wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
   wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
   wndClass.lpszMenuName   := nil;
   wndClass.lpszClassName  := 'GettingStarted';

   RegisterClass(wndClass);

   hWnd := CreateWindow(
      'GettingStarted',       // window class name
      'Customizing a Path Gradient',       // window caption
      WS_OVERLAPPEDWINDOW,    // window style
      Integer(CW_USEDEFAULT), // initial x position
      Integer(CW_USEDEFAULT), // initial y position
      Integer(CW_USEDEFAULT), // initial x size
      Integer(CW_USEDEFAULT), // initial y size
      0,                      // parent window handle
      0,                      // window menu handle
      hInstance,              // program instance handle
      nil);                   // creation parameters

   ShowWindow(hWnd, SW_SHOW);
   UpdateWindow(hWnd);

   while(GetMessage(msg, 0, 0, 0)) do
   begin
      TranslateMessage(msg);
      DispatchMessage(msg);
   end;
end.
