equalrgnu.pas

来自「Delphi Win32核心API参考光盘源码 本书包含了常用的Windows」· PAS 代码 · 共 57 行

PAS
57
字号
unit EqualRgnU;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormPaint(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormPaint(Sender: TObject);
var
  Region1, Region2: HRGN;  // holds the regions to be compared
begin
  {create an elliptical region}
  Region1 := CreateEllipticRgn(50, 50, 150, 150);

  {transform the region into a rectangular region. this function can be
   performed on any pre-existing region}
  SetRectRgn(Region1, 50, 50, 150, 150);

  {create a rectangular region identical to Region1}
  Region2 := CreateRectRgn(50, 50, 150, 150);

  {paint both regions red}
  Canvas.Brush.Color := clRed;
  PaintRgn(Canvas.Handle, Region1);
  PaintRgn(Canvas.Handle, Region2);

  {indicate if the regions are identical}
  if EqualRgn(Region1, Region2) then
    Label1.Caption := 'Regions Equal'
  else
    Label1.Caption := 'Regions Not Equal';

  {delete both regions as they are no longer needed}
  DeleteObject(Region1);
  DeleteObject(Region2);
end;

end.

⌨️ 快捷键说明

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