delphi实现透明窗口 代码
unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,F...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
procedure DoVisible;
procedure DoInvisible;
public
{ Public declarations }
end;
var
Form1:TForm1;
FullRgn:HRGN;
implementation
{$R *.dfm}
procedure TForm1.FormDestroy(Sender:TObject);
begin
DeleteObject(ClientRgn);
DeleteObject(FullRgn);
DeleteObject(CtlRgn);
end;
procedure TForm1.DoViSible;
begin
FullRgn:=CreateRectRgn(0,0,Width,Height);
CombineRgn(FullRgn,FullRgn,FullRgn,RGN_COPY);
SetWindowRgn(Handle,FullRgn,TRUE);
end;
procedure TForm1.FormCreate(Sender:TObject);
begin
DoInvisible;
end;
procedure TForm1.Button1Click(Sender:TObject);
begin
if Button1.Caption='Show' then begin
DoVisible;
Button1.Caption:='Hide';
end;
else begin
DoInvisible;
Button1.Caption:='Show';
end;
end;
procedure TForm1.Button2Click(Sender:TObject);
begin
Application.Terminate;
end;
procedure TForm1.FormResize(Sender:TObject);
begin
if Button1.Caption='Show' then
DoInvisible
else
DoVisible;
end;
end;
procedure TForm1.DoInvisible;
var
AControl:TControl;
A,Margin,X,Y,CtlX,CtlY:Interger;
begin
Margin:=(Width-ClientWidth) div 2;
FullRgn:=CreateRectRgn(0,0,Width,Height);
X:=Margin;
Y:=Height-ClientHeight-Margin;
ClientRgn:=CreateRectRgn(X,Y,X+ClientWidth,Y+ClientHeight);
CombineRgn(FullRgn,FullRgn,ClientRgn,RGN_DIFF);
for A:=0 to ControlCount-1 do begin
AControl:=Contrlos[A];
if(AControl is Twin Control)or(AControl is TGraphicControl)
then with AControl do begin
CtlX:=X+Left;
CtlY:=Y+Top;
CtlRgn:=CreateRectRgn(CtlX,CtlY,CtlX+Width,CtlY+Height);
CombineRgn(FullRgn,FullRgn,CtlRgn,RGN_OR);
end;
end;
程序有错误,请大家指导下,谢谢 展开
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
procedure DoVisible;
procedure DoInvisible;
public
{ Public declarations }
end;
var
Form1:TForm1;
FullRgn:HRGN;
implementation
{$R *.dfm}
procedure TForm1.FormDestroy(Sender:TObject);
begin
DeleteObject(ClientRgn);
DeleteObject(FullRgn);
DeleteObject(CtlRgn);
end;
procedure TForm1.DoViSible;
begin
FullRgn:=CreateRectRgn(0,0,Width,Height);
CombineRgn(FullRgn,FullRgn,FullRgn,RGN_COPY);
SetWindowRgn(Handle,FullRgn,TRUE);
end;
procedure TForm1.FormCreate(Sender:TObject);
begin
DoInvisible;
end;
procedure TForm1.Button1Click(Sender:TObject);
begin
if Button1.Caption='Show' then begin
DoVisible;
Button1.Caption:='Hide';
end;
else begin
DoInvisible;
Button1.Caption:='Show';
end;
end;
procedure TForm1.Button2Click(Sender:TObject);
begin
Application.Terminate;
end;
procedure TForm1.FormResize(Sender:TObject);
begin
if Button1.Caption='Show' then
DoInvisible
else
DoVisible;
end;
end;
procedure TForm1.DoInvisible;
var
AControl:TControl;
A,Margin,X,Y,CtlX,CtlY:Interger;
begin
Margin:=(Width-ClientWidth) div 2;
FullRgn:=CreateRectRgn(0,0,Width,Height);
X:=Margin;
Y:=Height-ClientHeight-Margin;
ClientRgn:=CreateRectRgn(X,Y,X+ClientWidth,Y+ClientHeight);
CombineRgn(FullRgn,FullRgn,ClientRgn,RGN_DIFF);
for A:=0 to ControlCount-1 do begin
AControl:=Contrlos[A];
if(AControl is Twin Control)or(AControl is TGraphicControl)
then with AControl do begin
CtlX:=X+Left;
CtlY:=Y+Top;
CtlRgn:=CreateRectRgn(CtlX,CtlY,CtlX+Width,CtlY+Height);
CombineRgn(FullRgn,FullRgn,CtlRgn,RGN_OR);
end;
end;
程序有错误,请大家指导下,谢谢 展开
1个回答
展开全部
procedure TForm1.FormDestroy(Sender:TObject);
begin
DeleteObject(ClientRgn);
DeleteObject(FullRgn);
DeleteObject(CtlRgn);
end;
procedure TForm1.DoViSible;
begin
FullRgn:=CreateRectRgn(0,0,Width,Height);
CombineRgn(FullRgn,FullRgn,FullRgn,RGN_COPY);
SetWindowRgn(Handle,FullRgn,TRUE);
end;
procedure TForm1.FormCreate(Sender:TObject);
begin
DoInvisible;
end;
procedure TForm1.Button1Click(Sender:TObject);
begin
if Button1.Caption='Show' then begin
DoVisible;
Button1.Caption:='Hide';
end; //这个分号不要
else begin
DoInvisible;
Button1.Caption:='Show';
end;
end;
procedure TForm1.Button2Click(Sender:TObject);
begin
Application.Terminate;
end;
procedure TForm1.FormResize(Sender:TObject);
begin
if Button1.Caption='Show' then
DoInvisible
else
DoVisible;
end;
end;
procedure TForm1.DoInvisible;
var
AControl:TControl;
A,Margin,X,Y,CtlX,CtlY:Interger; //Integer写错了.
begin
Margin:=(Width-ClientWidth) div 2;
FullRgn:=CreateRectRgn(0,0,Width,Height);
X:=Margin;
Y:=Height-ClientHeight-Margin;
ClientRgn:=CreateRectRgn(X,Y,X+ClientWidth,Y+ClientHeight); //没有定义ClientRgn,重新定义.ClientRgn:HRGN;
CombineRgn(FullRgn,FullRgn,ClientRgn,RGN_DIFF);
for A:=0 to ControlCount-1 do begin
AControl:=Contrlos[A];
if(AControl is Twin Control)or(AControl is TGraphicControl)
then with AControl do begin //Twin Control应该是TwinControl
CtlX:=X+Left;
CtlY:=Y+Top;
CtlRgn:=CreateRectRgn(CtlX,CtlY,CtlX+Width,CtlY+Height); //CtlRgn没有定义.
CombineRgn(FullRgn,FullRgn,CtlRgn,RGN_OR);
end;
//缺少一个end,加上即可.
end;
begin
DeleteObject(ClientRgn);
DeleteObject(FullRgn);
DeleteObject(CtlRgn);
end;
procedure TForm1.DoViSible;
begin
FullRgn:=CreateRectRgn(0,0,Width,Height);
CombineRgn(FullRgn,FullRgn,FullRgn,RGN_COPY);
SetWindowRgn(Handle,FullRgn,TRUE);
end;
procedure TForm1.FormCreate(Sender:TObject);
begin
DoInvisible;
end;
procedure TForm1.Button1Click(Sender:TObject);
begin
if Button1.Caption='Show' then begin
DoVisible;
Button1.Caption:='Hide';
end; //这个分号不要
else begin
DoInvisible;
Button1.Caption:='Show';
end;
end;
procedure TForm1.Button2Click(Sender:TObject);
begin
Application.Terminate;
end;
procedure TForm1.FormResize(Sender:TObject);
begin
if Button1.Caption='Show' then
DoInvisible
else
DoVisible;
end;
end;
procedure TForm1.DoInvisible;
var
AControl:TControl;
A,Margin,X,Y,CtlX,CtlY:Interger; //Integer写错了.
begin
Margin:=(Width-ClientWidth) div 2;
FullRgn:=CreateRectRgn(0,0,Width,Height);
X:=Margin;
Y:=Height-ClientHeight-Margin;
ClientRgn:=CreateRectRgn(X,Y,X+ClientWidth,Y+ClientHeight); //没有定义ClientRgn,重新定义.ClientRgn:HRGN;
CombineRgn(FullRgn,FullRgn,ClientRgn,RGN_DIFF);
for A:=0 to ControlCount-1 do begin
AControl:=Contrlos[A];
if(AControl is Twin Control)or(AControl is TGraphicControl)
then with AControl do begin //Twin Control应该是TwinControl
CtlX:=X+Left;
CtlY:=Y+Top;
CtlRgn:=CreateRectRgn(CtlX,CtlY,CtlX+Width,CtlY+Height); //CtlRgn没有定义.
CombineRgn(FullRgn,FullRgn,CtlRgn,RGN_OR);
end;
//缺少一个end,加上即可.
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询