关于Alpha Windos的问题,... (50分)

  • 主题发起人 主题发起人 yhw1999
  • 开始时间 开始时间
Y

yhw1999

Unregistered / Unconfirmed
GUEST, unregistred user!
我用下面代码实现了透明窗口,可是有个问题,我看见一个程序,它透明窗口下面的图标是<br>可以点击的,而我实现的透明窗口虽然看的见,但是在窗口下面的图标是不能点击的, <br>我该如何实现透明窗口下面的图标可点击呢, 也就是说看的见窗口,但是只是看的见,使用<br>的时候透明窗口就和不存在一样.<br><br>&nbsp; l:=getWindowLong(Handle, GWL_EXSTYLE);<br>&nbsp; l := l Or WS_EX_LAYERED;<br>&nbsp; SetWindowLong (handle, GWL_EXSTYLE, l);<br>&nbsp; SetLayeredWindowAttributes (handle, 0, 180, LWA_ALPHA);<br>
 
你重载WM_NCHITTEST的消息响应过程就可以了。
 
谢谢,但是我不知道该如何写代码呢?
 
Scarlette, 能再给我说详细点吗?
 
这样就OK了.<br><br>unit Unit1;<br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; ExtCtrls, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Panel1: TPanel;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormResize(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; procedure DoVisible;<br>&nbsp; &nbsp; procedure DoInvisible;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; FullRgn, ClientRgn, CtlRgn : THandle;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.DoInvisible;<br>var<br>&nbsp; AControl : TControl;<br>&nbsp; A, Margin, X, Y, CtlX, CtlY : Integer;<br>begin<br>&nbsp; Margin := ( Width - ClientWidth ) div 2;<br>&nbsp; FullRgn := CreateRectRgn(0, 0, Width, Height);<br>&nbsp; X := Margin;<br>&nbsp; Y := Height - ClientHeight - Margin;<br>&nbsp; ClientRgn := CreateRectRgn( X, Y, X + ClientWidth, Y + ClientHeight );<br><br>&nbsp; CombineRgn( FullRgn, FullRgn, ClientRgn, RGN_DIFF );<br><br>&nbsp; for A := 0 to ControlCount - 1 do begin<br>&nbsp; &nbsp; AControl := Controls[A];<br>&nbsp; &nbsp; if ( AControl is TWinControl ) or ( AControl is TGraphicControl )<br>&nbsp; &nbsp; &nbsp; &nbsp; then with AControl do begin<br>&nbsp; &nbsp; &nbsp; if Visible then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; CtlX := X + Left;<br>&nbsp; &nbsp; &nbsp; &nbsp; CtlY := Y + Top;<br>&nbsp; &nbsp; &nbsp; &nbsp; CtlRgn := CreateRectRgn( CtlX, CtlY, CtlX + Width, CtlY + Height );<br>&nbsp; &nbsp; &nbsp; &nbsp; CombineRgn( FullRgn, FullRgn, CtlRgn, RGN_OR );<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br><br>&nbsp; SetWindowRgn(Handle, FullRgn, TRUE);<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br><br>&nbsp; DeleteObject(ClientRgn);<br>&nbsp; DeleteObject(FullRgn);<br>&nbsp; DeleteObject(CtlRgn);<br>end;<br><br>procedure TForm1.DoVisible;<br>begin<br>&nbsp; FullRgn := CreateRectRgn(0, 0, Width, Height);<br>&nbsp; CombineRgn(FullRgn, FullRgn, FullRgn, RGN_COPY);<br>&nbsp; SetWindowRgn(Handle, FullRgn, TRUE);<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; DoInvisible;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; if Button1.Caption = 'Show Form' then begin<br>&nbsp; &nbsp; DoVisible;<br>&nbsp; &nbsp; Button1.Caption := '隐藏窗口';<br>&nbsp; end<br>&nbsp; else begin<br>&nbsp; &nbsp; DoInvisible;<br>&nbsp; &nbsp; Button1.Caption := '显示窗口';<br>&nbsp; end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; Application.Terminate;<br>end;<br><br>procedure TForm1.FormResize(Sender: TObject);<br>begin<br>&nbsp; if Button1.Caption = '显示窗口' then<br>&nbsp; &nbsp; DoInvisible<br>&nbsp; else<br>&nbsp; &nbsp; DoVisible;<br>end;<br>end.<br><br>呵 呵.兄弟加分啊.我没分了.不好意思.快啊.<br>
 
to ch_yahuu, 你实现的是把窗口区域透明了,但是窗口标题栏,边框 以及 窗口中的控件<br>还是不能实现透明啊.<br>&nbsp; &nbsp; 我想要的是窗完全透明的效果, 也就是说这个窗口就像一张墙纸一样,包括标题栏,边框<br>都是透明的.<br>&nbsp; &nbsp; 不过还是谢谢你,等这个问题结束了一定有你的分的.<br>
 
唉.你把form1.BorderStyle:=bsnone;不就可以了吗?<br><br>
 
不是的,这样确实是没有边框了,但是那些框件还是没有透明啊,我说的时不仅透明,而且<br>控件下面的东西也是可以直接操作的
 
绝对可以啊.我试过的.在form1属性里将borderstyle设为bsnone<br><br>我试过的.一点问题都没有.<br>窗体是完全透明的.而且透明窗体下的图标啊.什么的都是可以使用的.就像没有窗体一样.<br>我用的是win98.不知你用的是什么你再好好看看
 
我是用的 Win2000 ,那我在到 win98 下面试一试再说吧, <br>另外 , 我是在 这里下载的 http://www.genius-software.com/cn/download/index.htm<br>幻想桌面 这处程序中看到的功能, 它里面的图片 和 便签 都是使用了我说的那种透明<br>方式
 
我在98下面试了,和在2000下面效果一样,窗口中的控件不能透明
 
后退
顶部