- unit nRdUnit1;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ExtCtrls;
- type
- TForm1 = class(TForm)
- Image1: TImage;
- Button1: TButton;
- Label1: TLabel;
- procedure Button1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- elli_rgn,fourE_rgn,tri_rgn:hrgn;//指向椭圆形、四边形、三角形的区域变量
- implementation
- {$R *.DFM}
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- //释放三个区域指针变量所占内存
- DeleteObject(Elli_rgn);
- DeleteObject(tri_rgn);
- DeleteObject(fourE_rgn);
- application.terminate;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- var
- thepoint:array [1..8] of tpoint;//存储多边形顶点坐标
- count:integer;
- pointnum:array [1..2] of integer;
- begin
- //四边形顶点坐标,首末点封闭
- thepoint[1]:=point(135,99);
- thepoint[2]:=point(105,183);
- thepoint[3]:=point(129,201);
- thepoint[4]:=point(188,92);
- thepoint[5]:=point(135,99);
- count:=5;//四边形顶点数目,首末点为一点
- fourE_rgn:=CreatePolygonRgn(thepoint,count,WINDING);//生成四边形区域
- elli_rgn:=CreateEllipticRgn(64,221,231,263);// 生成椭圆形区域
- //第一个三角形顶点坐标
- thepoint[1]:=point(118,67);
- thepoint[2]:=point(32,28);
- thepoint[3]:=point(17,90);
- thepoint[4]:=point(118,67);
- //第二个三角形顶点坐标
- thepoint[5]:=point(155,44);
- thepoint[6]:=point(202,91);
- thepoint[7]:=point(277,44);
- thepoint[8]:=point(155,44);
- pointnum[1]:=4;//第一个三角形顶点数目
- pointnum[2]:=4;//第二个三角形顶点数目
- count:=2;//三角形数目
- //生成由两个三角形构成的三角形区域
- tri_rgn:=CreatePolyPolygonRgn(thepoint,pointnum,count,WINDING);
- end;
- procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- var
- flag1,flag2,flag3:boolean;
- begin
- //三个标志变量以判明鼠标没有击中热点
- flag1:=false; flag2:=false; flag3:=false;
- //热点的判断
- if ptinregion(Elli_rgn,x,y) then label1.caption:='椭圆'
- else flag1:=true;
- if ptinregion(tri_rgn,x,y) then label1.caption:='三角形'
- else flag2:=true;
- if ptinregion(fourE_rgn,x,y) then label1.caption:='四边形'
- else flag3:=true;
- if (flag1 and flag2 and flag3) then label1.caption:='鼠标没有击中热点';
- end;
- end.
用Delphi实现热点
最新推荐文章于 2025-08-11 12:01:14 发布
