F
foolboy007
Unregistered / Unconfirmed
GUEST, unregistred user!
我在《电脑爱好者》去年10期上看到一个用delphi实现半透明效果的程序。
程序中说在98下测试通过。但是,我在win2000下(我没装98),却实现不了半透明,
程序能正确编译。不知为何?请大家看看:
----------
在form上放一个计时器(命名为tmrshowbitmap, interval=20)
一个image控件(命名为imgsrc,autosize为true).
代码如下:
unit stp;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
jpeg, ExtCtrls;
type
TFrmsemitransparent = class(TForm)
tmrshowbitmap: TTimer;//控制透明度的时钟
Imgsrc: TImage;
procedure FormCreate(Sender: TObject);
procedure tmrshowbitmaptimer(Sender:TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure onErasebkgnd(var Message:TWMEraseBkgnd); Message WM_EraseBkgnd;//使用message关键字进行消息截获。
end;
var
Frmsemitransparent: TFrmsemitransparent;
bf:_blendfunction;//alpha透明结构函数
nwidth:integer;
nheight:integer;
ncount:integer;
implementation
{$R *.DFM}
procedure TfrmSemiTransparent.onEraseBkgnd(var Message:TWMEraseBkgnd);
begin
Message.Result:=1;
end;
procedure Tfrmsemitransparent.tmrshowbitmaptimer(sender:Tobject);
begin
ncount:=nCount+1;
if nCount>250 then
begin
tmrshowbitmap.enabled:=false;
frmsemiTransparent.Hide ;
frmsemiTransparent.Close;
end;
bf.SourceConstantAlpha:=ncount;
Alphablend(frmsemitransparent.canvas.handle,
0,0,nwidth,nheight,imgsrc.canvas.handle,
0,0,nwidth,nheight,bf);
end;
procedure TFrmsemitransparent.FormCreate(Sender: TObject);
begin
frmsemitransparent.BorderStyle:=bsnone;
frmsemitransparent.Position:=podesktopcenter;
nwidth:=imgsrc.width;
nheight:=imgsrc.height;
ncount:=0;
bf.blendop:=ac_src_over;
bf.blendflags:=0;
bf.sourceconstantalpha:=ncount;
bf.alphaformat:=0;
setwindowpos(handle,hwnd_top,0,0,nwidth-1,nheight-1,0);
tmrshowbitmap.enabled:=true;
end;
end.
程序中说在98下测试通过。但是,我在win2000下(我没装98),却实现不了半透明,
程序能正确编译。不知为何?请大家看看:
----------
在form上放一个计时器(命名为tmrshowbitmap, interval=20)
一个image控件(命名为imgsrc,autosize为true).
代码如下:
unit stp;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
jpeg, ExtCtrls;
type
TFrmsemitransparent = class(TForm)
tmrshowbitmap: TTimer;//控制透明度的时钟
Imgsrc: TImage;
procedure FormCreate(Sender: TObject);
procedure tmrshowbitmaptimer(Sender:TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure onErasebkgnd(var Message:TWMEraseBkgnd); Message WM_EraseBkgnd;//使用message关键字进行消息截获。
end;
var
Frmsemitransparent: TFrmsemitransparent;
bf:_blendfunction;//alpha透明结构函数
nwidth:integer;
nheight:integer;
ncount:integer;
implementation
{$R *.DFM}
procedure TfrmSemiTransparent.onEraseBkgnd(var Message:TWMEraseBkgnd);
begin
Message.Result:=1;
end;
procedure Tfrmsemitransparent.tmrshowbitmaptimer(sender:Tobject);
begin
ncount:=nCount+1;
if nCount>250 then
begin
tmrshowbitmap.enabled:=false;
frmsemiTransparent.Hide ;
frmsemiTransparent.Close;
end;
bf.SourceConstantAlpha:=ncount;
Alphablend(frmsemitransparent.canvas.handle,
0,0,nwidth,nheight,imgsrc.canvas.handle,
0,0,nwidth,nheight,bf);
end;
procedure TFrmsemitransparent.FormCreate(Sender: TObject);
begin
frmsemitransparent.BorderStyle:=bsnone;
frmsemitransparent.Position:=podesktopcenter;
nwidth:=imgsrc.width;
nheight:=imgsrc.height;
ncount:=0;
bf.blendop:=ac_src_over;
bf.blendflags:=0;
bf.sourceconstantalpha:=ncount;
bf.alphaformat:=0;
setwindowpos(handle,hwnd_top,0,0,nwidth-1,nheight-1,0);
tmrshowbitmap.enabled:=true;
end;
end.