一个透明窗体的例子.
假定背景色单一.
var
Form1: TForm1;
BackColor:TColor;
implementation
{$R *.DFM}
{$R Icon.res}
procedure TForm1.FormCreate(Sender: TObject);
begin
BackColor:=Image1.Canvas.Pixels[2,2];//假定背景颜色是 Image1.Canvas.Pixels[2,2]的颜色
SetWindowLong(Application.Handle,GWL_ExStyle,WS_EX_Toolwindow);
screen.Cursors[lovecursor]:=loadcursor(hInstance,'newcursor');
cursor:=lovecursor;
installIcon;
end;
procedure TForm1.FormShow(Sender: TObject);
var
MyRgn, ClientRgn, ButtonRgn,bmpRgn: THandle;
Margin, X, Y: Integer;
p : Tpoint;
begin
Margin := (Width - ClientWidth) div 2;
MyRgn := CreateRectRgn(0, 0, Width, Height);
X := Margin;
Y := Height - ClientHeight - Margin;
ClientRgn := CreateRectRgn(X, Y, X + ClientWidth, Y + ClientHeight);
CombineRgn(MyRgn, MyRgn, ClientRgn, RGN_XOR);
for x:=0 to Image1.width-1 do
for y:=0 to Image1.height-1 do
begin
if Image1.Canvas.Pixels[x,y]<> BackColor then //这里判断每个像素点
begin
bmpRgn:= CreateRectRgn(x,y,x+1,y+1);
CombineRgn(MyRgn,MyRgn,bmpRgn,RGN_XOR);
end;
end;
SetWindowRgn(Handle, MyRgn, True);
end;