⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getpathu.pas

📁 DelphiWin32核心API参考光盘内容.是学习书籍中的源码,便于学习.
💻 PAS
字号:
unit GetPathU;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
type
  TPointsArray = array[0..0] of TPoint;   // array of TPoints storing vertices
  TTypesArray = array[0..0] of Byte;      // array of bytes storing vertex types
var
  CurvePts: array[0..3] of TPoint;        // array of points defining the curve
  Points: ^TPointsArray;                  // pointer to array of points
  Types: ^TTypesArray;                    // pointer to array of bytes
  PtCount: Integer;                       // the number of points in the path
  iCount: Integer;                        // general loop control variable
  FormDC: HDC;                            // a handle to the form's DC
  ThePen, OldPen: HPEN;                   // pen handles
  InfoString: String;                     // a string describing a point
begin
  {define points used to draw a b閦ier curve}
  CurvePts[0] := Point(30, 80);
  CurvePts[1] := Point(55, 30);
  CurvePts[2] := Point(105, 30);
  CurvePts[3] := Point(130, 80);

  {retrieve a handle to the form's device context}
  FormDC := GetDC(Form1.Handle);

  {begin a path bracket}
  BeginPath(FormDC);

  {draw a b閦ier curve}
  PolyBezier(FormDC, CurvePts, 4);

  {end the path bracket}
  EndPath(FormDC);

  {convert the path into a series of line segments}
  FlattenPath(FormDC);

  {retrieve the number of points defining the path}
  PtCount := GetPath(FormDC, Points^, Types^, 0);

  {allocate enough memory to store the points and their type flags}
  GetMem(Points, SizeOf(TPoint)*PtCount);
  GetMem(Types, PtCount);

  {retrieve the points and vertex types of the path}
  GetPath(FormDC, Points^, Types^, PtCount);

  {for each point in the path...}
  for iCount := 0 to PtCount-1 do
  begin
    {record the point's coordinates}
    InfoString := 'X: '+IntToStr(Points[iCount].X)+
                  ' Y: '+IntToStr(Points[iCount].Y);

    {record the type of point}
    case (Types[iCount] and not PT_CLOSEFIGURE) of
      PT_MOVETO:   InfoString := InfoString+' Type: MoveTo';
      PT_LINETO:   InfoString := InfoString+' Type: LineTo';
      PT_BEZIERTO: InfoString := InfoString+' Type: BezierTo';
    end;

    {since the PT_CLOSEFIGURE flag can be combined with the other flags, check
     it seperately and record if the figure in the path is closed}
    if (Types[iCount] and PT_CLOSEFIGURE)=PT_CLOSEFIGURE then
      InfoString := InfoString+', Close Figure';

    {display the information about this point in the path}
    ListBox1.Items.Add(InfoString);
  end;

  {create and select a pen into the device context}
  ThePen := CreatePen(PS_SOLID, 1, clBlack);
  OldPen := SelectObject(FormDC, ThePen);

  {draw the path}
  StrokePath(FormDC);

  {the pen is no longer needed, so delete it}
  SelectObject(FormDC, OldPen);
  DeleteObject(ThePen);

  {free the memory used to store the points and vertex types}
  FreeMem(Points);
  FreeMem(Types);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -