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;

程序有错误,请大家指导下,谢谢
展开
 我来答
yueyun889
2008-06-04 · TA获得超过725个赞
知道小有建树答主
回答量:539
采纳率:0%
帮助的人:768万
展开全部
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;
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式