📄 createpolypolygonrgnu.pas
字号:
unit CreatePolyPolygonRgnU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
HotSpotRgn: HRGN; // holds the multiple polygon region
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
PolyPoints: array[0..11] of TPoint; // holds the points of the polygons
VertexCounts: array[0..1] of Integer; // holds the vertex counts
begin
{define one polygon in the region}
PolyPoints[0] := Point(68, 80);
PolyPoints[1] := Point(76, 72);
PolyPoints[2] := Point(87, 80);
PolyPoints[3] := Point(86, 96);
PolyPoints[4] := Point(100, 96);
PolyPoints[5] := Point(100, 160);
PolyPoints[6] := Point(68, 160);
{define another polygon in the region}
PolyPoints[7] := Point(173, 53);
PolyPoints[8] := Point(184, 66);
PolyPoints[9] := Point(184, 146);
PolyPoints[10] := Point(160, 146);
PolyPoints[11] := Point(160, 66);
{indicate that the firs polygon consists of 7 points, and the second
consists of 5 points}
VertexCounts[0] := 7;
VertexCounts[1] := 5;
{create the multiple polygon region}
HotSpotRgn := CreatePolyPolygonRgn(PolyPoints, VertexCounts, 2, WINDING);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
{invert the area defined by the multiple polygon region}
InvertRgn(Canvas.Handle, HotSpotRgn);
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
TranslatedPt: TPoint; // holds a form specific coordinate
begin
{since the region is defined in logical coordinates relative to the form,
the indicated location of the mouse click must be translated appropriately}
TranslatedPt := Image1.ClientToScreen(Point(X,Y));
TranslatedPt := Form1.ScreenToClient(TranslatedPt);
{indicate if the point is within the 'hotspot' area defined by the
multiple polygon region}
if PtInRegion(HotSpotRgn, TranslatedPt.X, TranslatedPt.Y) then
Caption := 'Clicked on a hotspot'
else
Caption := 'No hot spot clicked';
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{delete the region}
DeleteObject(HotSpotRgn);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -