home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Constructing and Drawing Curves / Drawing Cardinal Splines / App3 / GDITEST60.dpr
Encoding:
Text File  |  2003-10-15  |  2.5 KB  |  97 lines

  1. program GDITEST60;
  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.   Pen: TGPPen;
  14. const
  15.   points: array[0..4] of TGPPoint =
  16.     ((x: 20 ; y: 50),
  17.      (x: 100; y: 10),
  18.      (x: 200; y: 100),
  19.      (x: 300; y: 50),
  20.      (x: 400; y: 80));
  21. begin
  22.   graphics := TGPGraphics.Create(DC);
  23.   Pen := TGPPen.Create(MakeColor(255, 0, 0, 255));
  24.   graphics.DrawCurve(pen, PGPPoint(@points), 5, 0.0); // tension 0.0
  25.   graphics.DrawCurve(pen, PGPPoint(@points), 5, 0.6); // tension 0.6
  26.   graphics.DrawCurve(pen, PGPPoint(@points), 5, 1.0); // tension 1.0
  27.   Pen.Free;
  28.   graphics.Free;
  29. end;
  30.  
  31.  
  32. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  33. var
  34.   Handle: HDC;
  35.   ps: PAINTSTRUCT;
  36. begin
  37.   case message of
  38.     WM_PAINT:
  39.       begin
  40.         Handle := BeginPaint(Wnd, ps);
  41.         OnPaint(Handle);
  42.         EndPaint(Wnd, ps);
  43.         result := 0;
  44.       end;
  45.  
  46.     WM_DESTROY:
  47.       begin
  48.         PostQuitMessage(0);
  49.         result := 0;
  50.       end;
  51.  
  52.    else
  53.       result := DefWindowProc(Wnd, message, wParam, lParam);
  54.    end;
  55. end;
  56.  
  57. var
  58.   hWnd     : THandle;
  59.   Msg      : TMsg;
  60.   wndClass : TWndClass;
  61. begin
  62.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  63.    wndClass.lpfnWndProc    := @WndProc;
  64.    wndClass.cbClsExtra     := 0;
  65.    wndClass.cbWndExtra     := 0;
  66.    wndClass.hInstance      := hInstance;
  67.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  68.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  69.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  70.    wndClass.lpszMenuName   := nil;
  71.    wndClass.lpszClassName  := 'GettingStarted';
  72.  
  73.    RegisterClass(wndClass);
  74.  
  75.    hWnd := CreateWindow(
  76.       'GettingStarted',       // window class name
  77.       'Drawing Cardinal Splines',       // window caption
  78.       WS_OVERLAPPEDWINDOW,    // window style
  79.       Integer(CW_USEDEFAULT), // initial x position
  80.       Integer(CW_USEDEFAULT), // initial y position
  81.       Integer(CW_USEDEFAULT), // initial x size
  82.       Integer(CW_USEDEFAULT), // initial y size
  83.       0,                      // parent window handle
  84.       0,                      // window menu handle
  85.       hInstance,              // program instance handle
  86.       nil);                   // creation parameters
  87.  
  88.    ShowWindow(hWnd, SW_SHOW);
  89.    UpdateWindow(hWnd);
  90.  
  91.    while(GetMessage(msg, 0, 0, 0)) do
  92.    begin
  93.       TranslateMessage(msg);
  94.       DispatchMessage(msg);
  95.    end;
  96. end.
  97.