请问在Win2000下窗体可以透明. Win98 下却不行?(50分)

  • 主题发起人 主题发起人 summax
  • 开始时间 开始时间
S

summax

Unregistered / Unconfirmed
GUEST, unregistred user!
我是设定窗体的 TransparentColor 为真来实现的.在Win98 下却不能透.请问要怎么做.在98下也可以透明??
 
窗体透明在win2000下面系统支持这样的特性,98下面不支持呀!
 
很多win2000底下的API和函数包Win98也不支持啊。
很正常,找一个win98底下也可以用的透明控件吧。
 
Win2000下的窗体透明由API函数:SetLayeredWindowAttributes 进行
它在Win2K以前未实现。
Win2K以前也不支持WS_EX_LAYERED风格的窗体。
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2509733
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1687505
 
API的问题
 
那怎么样才能在Win98 下也能用呢
 
其实最简单的方法是:
在FormCreate中,添加代码:
Brush.Style:=bsClear;
即可,注意,不是Canvas.Brush.Style!
procedure TForm1.FormCreate(Sender: TObject);
var p:longint;
begin
p:=GetWindowLong(handle,GWL_STYLE);//获取窗体属性
SetWindowLong(handle,GWL_EXSTYLE,p+WS_EX_TRANSPARENT);//设置新属性

form1.Refresh;
end;
***************************
To make a form transparent you should put these 2 lines in form's creation procedure:

procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Brush.Style:=bsClear;
Form1.BorderStyle:=bsNone;
end;

If you use only that you will notice that the form is transparent but if you put something
over it, it will not clear its own background and traces of that object will be left on the
form. To solve that you need to make sure that the transparent form's Paint procedure (WM_PAINT)
will be called last. To do that you need to override the TWinControl (TForm's ancestor)
CreateParams procedure and set the Form's extended style (ExStyle) to WS_EX_TRANSPARENT.

Here's the full code for making a form transparent:

type
TForm1 = class(TForm)
procedure CreateParams(var Params:TCreateParams); override;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.CreateParams(var Params:TCreateParams);
Begin
inherited CreateParams(Params);
Params.ExStyle:=WS_EX_TRANSPARENT;
End;

procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Brush.Style:=bsClear;
Form1.BorderStyle:=bsNone;
end;
这样试试???
 
多人接受答案了。
 
后退
顶部