从win2k系统开始,ms就在操作系统中加入了一些API,利用这些api可以实现窗体(form)的半透明。
具体代码如下:
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
const
WS_EX_LAYERED=$80000;
AC_SRC_OVER=$0;
AC_SRC_ALPHA=$1;
AC_SRC_NO_PREMULT_ALPHA=$1;
AC_SRC_NO_ALPHA=$2;
AC_DST_NO_PREMULT_ALPHA=$10;
AC_DST_NO_ALPHA=$20;
LWA_COLORKEY=$1;
LWA_ALPHA=$2;
ULW_COLORKEY=$1 ;
ULW_ALPHA=$2 ;
ULW_OPAQUE=$4 ;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function SetLayeredWindowAttributes(hwnd:HWND; crKey:Longint;
bAlpha:byte; dwFlags:longint ):longint; stdcall; external user32;//函数声明
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
l:longint;
begin
l:=getWindowLong(Handle, GWL_EXSTYLE);
l:= l Or WS_EX_LAYERED;
SetWindowLong (handle, GWL_EXSTYLE, l);
SetLayeredWindowAttributes (handle, 0, 180, LWA_ALPHA);//第二个参数是指定透明颜色
//第二个参数若为0则使用第四个参数设置alpha值,从0到255
end;
end.
窗体的全透明:在form的 create 中放入下面的代码即可实现。
TransparentColor:=True;
TransparentColorValue:=100;
Color:=Form1.TransparentColorValue;
若转载请注明出处: Spirit's Home
本文地址: http://www.7788sky.cn/post/delphictbtm.html
0 Response to “delphi利用api实现窗体的半透明及透明”