不规则窗口的实现,用下面的程序
unit s1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure FormMouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
procedure FormPaint(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
const
MyRgn : Array[1..8] of integer =(2,135,115,22,228,135,2,135);
//区域坐标
var
mx,my: integer;
HR: HRGN;
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Color := clblack;
Form1.Canvas.Font.Size:=12;
Form1.Canvas.Font.Style:=Form1.Canvas.Font.Style + [fsBold];
Form1.Canvas.Font.Color := clred;
HR:=CreatePolygonRgn(MyRgn,4,ALTERNATE);
//创建一个区域
SetWindowRgn(Form1.Handle,HR,False);
// 设置窗口区域
UpdateWindow(Form1.Handle);
//更新窗口
end;
procedure TForm1.FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
mx:=x;
my:=y;
end;
procedure TForm1.FormMouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
begin
if ssLeft in shift then
begin
Form1.Left := Form1.Left - mx+x;
Form1.Top := Form1.Top - My +y;
end;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
Form1.Canvas.TextOut(50,60,'Alt+F4 to Quit');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DeleteObject(HR);
//删除区域
end;
end.