精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Delphi>>图形界面和窗体>>Re:关于在delphi下实现透明窗体的问题

主题:Re:关于在delphi下实现透明窗体的问题
发信人: xjg(七彩阳光)
整理人: teleme(2001-03-25 20:38:41), 站内信件
【 在 derago 的大作中提到:】
:在网上泡了一整天,发现不外乎两种方式
:1、其实 ,很简单就加一句话,却被很多作者写了一满篇,气的人吐血。
:brush.stely:=bsclear;简单吧,马上你就要伤心了。原来这个窗口只是一瞬间的透明,恶心。
:2、说了一大堆关于api的东东,可是非常负杂,不知是我蠢,还是作者故能玄虚,反正form的showintaskbar我是没找到,还请大家指教,最好是能找一个最简单易懂的源代码。
:据说还有第三种方法,估计也好不到哪里去,方法是用一个bmp外加一个mask估计也不是很好。
:
:......

如果你用的是WIN2K, 有现成的API:


object Form1: TForm1
  Left = 353
  Top = 171
  Width = 347
  Height = 196
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  FormStyle = fsStayOnTop
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 60
    Top = 100
    Width = 195
    Height = 64
    Caption = '你好!'
    Font.Charset = ANSI_CHARSET
    Font.Color = clMaroon
    Font.Height = -64
    Font.Name = '宋体'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Button1: TButton
    Left = 64
    Top = 36
    Width = 75
    Height = 25
    Caption = 'Test'
    TabOrder = 0
    OnClick = Button1Click
  end
  object BitBtn1: TBitBtn
    Left = 224
    Top = 108
    Width = 75
    Height = 25
    TabOrder = 1
    Kind = bkClose
  end
end



unit Main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    Button1: TButton;
    BitBtn1: TBitBtn;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

function SetLayeredWindowAttributes(Handle: THandle; crey, bAlpha: Byte; dwFlags: Integer): LongInt; stdcall;

var
  Form1: TForm1;
const
  WS_EX_LAYERED = $80000;
  WS_EX_TRANSPARENT = $20;
  LWA_ALPHA = $2;

implementation

{$R *.DFM}
{$EXTERNALSYM SetLayeredWindowAttributes}
function SetLayeredWindowAttributes; external user32 name 'SetLayeredWindowAttributes';


procedure TForm1.Button1Click(Sender: TObject);
var
  bTrans: Byte;
  OldStyle: Integer;
begin
  OldStyle := GetWindowLong(Handle, GWL_EXSTYLE);
  SetWindowLong(Handle, GWL_EXSTYLE, OldStyle or WS_EX_LAYERED);
  bTrans := 100; //透明度 0-255
  SetLayeredWindowAttributes(Handle, 0, bTrans, LWA_ALPHA);
end;

end.



 


----

[关闭][返回]