WinAPI: MoveToEx 与 LineTo - 绘制直线

//声明:
MoveToEx(
  DC: HDC;         {设备环境句柄}
  p2, p3: Integer; {坐标}
  p4: PPoint       {用于保存 p2、p3 值的 TPoint 结构的指针}
): BOOL;

LineTo(
  DC: HDC;      {设备环境句柄}
  X, Y: Integer {直线终点坐标}
): BOOL;

 
 
 
 
 

 

 
  

//举例:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var
  flag: Boolean;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  MoveToEx(Canvas.Handle, X, Y, nil);
  flag := True;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if flag then LineTo(Canvas.Handle, X, Y);
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  flag := False;
end;

end.

 
 
 
 
 

 

 
  

//效果图:
WinAPI: MoveToEx 与 LineTo - 绘制直线

你可能感兴趣的:(WinAPI: MoveToEx 与 LineTo - 绘制直线)