📄 regiondatau.pas
字号:
unit RegionDataU;
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);
var
TheRegion: HRGN; // holds the region
RegionDataSize: DWORD; // holds the size of region information
RegionData: Pointer; // a pointer to the region information
iCount: Integer; // general loop control variable
RectPointer: ^TRect; // a pointer used to extract rectangle coordinates
begin
{create a round rectangular region}
TheRegion := CreateRoundRectRgn(10, 10, 110, 110, 30, 30);
{initialize the canvas's brush and draw the region}
Canvas.Brush.Color := clRed;
FillRgn(Canvas.Handle, TheRegion, Canvas.Brush.Handle);
{retrieve the size of the buffer required to hold the region data,
and allocate the specified memory}
RegionDataSize := GetRegionData(TheRegion, 0, NIL);
GetMem(RegionData, RegionDataSize);
{retrieve the information about the round rectangular region}
GetRegionData(TheRegion, RegionDataSize, RegionData);
{display the information}
with ListBox1.Items do
begin
{display the number of rectangles in the region, and the size of
the region's bounding rectangle}
Add('Number of rectangles: '+IntToStr(TRgnData(RegionData^).rdh.nCount));
Add('Region bounding rectangle -');
Add('Left: '+IntToStr(TRgnData(RegionData^).rdh.rcBound.Left)+
' Top: '+IntToStr(TRgnData(RegionData^).rdh.rcBound.Top)+
' Right: '+IntToStr(TRgnData(RegionData^).rdh.rcBound.Right)+
' Bottom: '+IntToStr(TRgnData(RegionData^).rdh.rcBound.Bottom));
Add('');
{initialize a pointer to the address of the buffer containing the
coordinates of the rectangles defining the region}
RectPointer := @TRgnData(RegionData^).Buffer;
{set the canvas's pen to a different color so the rectangles will show}
Canvas.Pen.Color := clBlack;
{loop through the indicated number of rectangles}
for iCount := 0 to TRgnData(RegionData^).rdh.nCount-1 do
begin
{the RectPointer pointer by definition will typecast the values in the
Buffer array as a TRect, thereby allowing the application to extract
the necessary members}
Add('Rect: '+IntToStr(iCount)+
' - L: '+IntToStr(RectPointer^.Left)+
', T: '+IntToStr(RectPointer^.Top)+
', R: '+IntToStr(RectPointer^.Right)+
', B: '+IntToStr(RectPointer^.Bottom));
{draw this specific rectangle over the region}
Canvas.Rectangle(RectPointer^.Left, RectPointer^.Top, RectPointer^.Right,
RectPointer^.Bottom);
{since the pointer is a pointer to a TRect, incrementing its value will
move it forward by the size of a TRect structure. thus, it will be
pointing to the next rectangle in the series}
Inc(RectPointer);
end;
end;
{delete the region and free the allocated memory}
FreeMem(RegionData);
DeleteObject(TheRegion);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -