unit UFramePanel;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TFramePanel =
class(TPanel)
private
FFrameWidth : Integer;
procedure SetFrameWidth(
const Value: Integer);
procedure UpdateWindowRegion;
public
constructor Create(AOwner: TComponent);
override;
published
property FrameWidth : Integer
read FFrameWidth
write SetFrameWidth;
end;
implementation
function GetFramedRegion(Width, Height, FrameWidth : Integer): HWnd;
const
count = 11;
var
points :
array[0..(count-1)]
of TPoint;
begin
points[0].X := 0;
points[0].Y := 0;
points[1].X := FrameWidth;
points[1].Y := FrameWidth;
points[2].X := FrameWidth;
points[2].Y := Height - FrameWidth;
points[3].X := Width - FrameWidth;
points[3].Y := Height - FrameWidth;
points[4].X := Width - FrameWidth;
points[4].Y := FrameWidth;
points[5].X := FrameWidth;
points[5].Y := FrameWidth;
points[6].X := 0;
points[6].Y := 0;
points[7].X := Width;
points[7].Y := 0;
points[8].X := Width;
points[8].Y := Height;
points[9].X := 0;
points[9].Y := Height;
points[10].X := 0;
points[10].Y := 0;
Result := CreatePolygonRgn(points, count, ALTERNATE);
{ ALTERNATE, WINDING }
//ShowMessage(SysErrorMessage(GetLastError));
end;
constructor TFramePanel.Create(AOwner: TComponent);
begin
inherited;
FFrameWidth := 0;
end;
procedure TFramePanel.UpdateWindowRegion;
var
HRegion : HWnd;
begin
if (Width > 2)
and (Height > 2)
then
begin
HRegion := GetFramedRegion(width, height, FFrameWidth);
SetWindowRGN(
Handle, HRegion, True);
end;
end;
procedure TFramePanel.SetFrameWidth(
const Value: Integer);
begin
if Value <= 1
then
FFrameWidth := 2
else if (Value >= (width
div 2))
then
FFrameWidth := (width
div 2) -1
else
FFrameWidth := Value;
UpdateWindowRegion;
end;
end.