如何制作能让鼠标穿透的窗口? ( 积分: 100 )

  • 主题发起人 主题发起人 cnhbtszw
  • 开始时间 开始时间
C

cnhbtszw

Unregistered / Unconfirmed
GUEST, unregistred user!
如何制作能让鼠标穿透的窗口?就是说鼠标单击该窗口时,被该窗口遮盖的下一层的该位置接受鼠标单击,并做出响应,也就是相当于没有这个窗口一样。
 
如何制作能让鼠标穿透的窗口?就是说鼠标单击该窗口时,被该窗口遮盖的下一层的该位置接受鼠标单击,并做出响应,也就是相当于没有这个窗口一样。
 
做个透明窗体
 
procedure THintWindow.WMNCHitTest(var Message: TWMNCHitTest);<br>begin<br> &nbsp;Message.Result := HTTRANSPARENT;<br>end;
 
可以直接在事件操作
 
to xuxiaohan:感谢您的参与,我按照您的代码试了一下,鼠标并没有穿透该窗口到达下一层窗口。可否说得再详细一些?<br>to chen_liang 可否再详细一些?有代码最好了,谢谢参与.
 
我用的是winxp professional.
 
各位,如果嫌分少的话,我可以再加分
 
给分吧, 测试通过。 有分加更加好 [:D][:D]<br><br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp; &nbsp;procedure CreateParams(var Params: TCreateParams); override;<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>const<br> &nbsp;WS_EX_LAYERED = $80000;<br> &nbsp;WS_EX_TRANSPARENT = $20;<br> &nbsp;LWA_ALPHA = $2;<br>var<br> &nbsp;OldStyle: Integer;<br>begin<br> &nbsp;OldStyle := GetWindowLong(Handle, GWL_EXSTYLE);<br> &nbsp;SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or<br> &nbsp; &nbsp;WS_EX_LAYERED);<br> &nbsp;SetLayeredWindowAttributes(Handle, 0, 125, LWA_ALPHA);<br> &nbsp;SetWindowLong(Handle, GWL_EXSTYLE, OldStyle or WS_EX_LAYERED or<br> &nbsp; &nbsp;WS_EX_TRANSPARENT or WS_EX_TOPMOST);<br>end;<br><br><br>procedure TForm1.CreateParams(var Params: TCreateParams);<br>begin<br> &nbsp;inherited CreateParams(Params);<br> &nbsp;with params do<br> &nbsp;begin<br> &nbsp; &nbsp;Style:=WS_POPUP or WS_BORDER;<br> &nbsp; &nbsp;ExStyle := WS_EX_TOPMOST or WS_EX_NOACTIVATE or WS_EX_WINDOWEDGE;<br> &nbsp;end;<br>end;<br><br>end.
 
非常非常感谢,你太棒了,还有两个小问题想请教,<br>1、如何不让该窗口透明?<br>2、如何让该窗口恢复到正常状态?<br><br>非常非常感谢,一定加分。
 
不知道怎么在往上添分,以后再说,非常感谢xuxiaohan
 
可以让窗口不透明的,我让它透明, 是为了让你更好的看到这种效果。<br>procedure TForm1.Button1Click(Sender: TObject);<br>const<br> &nbsp;WS_EX_LAYERED = $80000;<br> &nbsp;WS_EX_TRANSPARENT = $20;<br> &nbsp;LWA_ALPHA = $2;<br>var<br> &nbsp;OldStyle: Integer;<br>begin<br> &nbsp;OldStyle := GetWindowLong(Handle, GWL_EXSTYLE);<br> &nbsp;SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or<br> &nbsp; &nbsp;WS_EX_LAYERED);<br> &nbsp;SetLayeredWindowAttributes(Handle, 0, [blue]255[/blue], LWA_ALPHA);<br> &nbsp;SetWindowLong(Handle, GWL_EXSTYLE, OldStyle or WS_EX_LAYERED or<br> &nbsp; &nbsp;WS_EX_TRANSPARENT or WS_EX_TOPMOST);<br>end;<br><br>//********************<br>unit Unit2;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls;<br><br>type<br> &nbsp;TForm2 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Button2: TButton;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure Button2Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form2: TForm2;<br><br>implementation<br><br>uses Unit1;<br><br>{$R *.dfm}<br><br>procedure TForm2.Button1Click(Sender: TObject);<br>var<br> &nbsp;OldStyle: Integer;<br>begin<br> &nbsp;//恢复原来的样子<br> &nbsp;OldStyle := GetWindowLong(Handle, GWL_EXSTYLE);<br> &nbsp;SetWindowLong(Form1.Handle, GWL_EXSTYLE, oldStyle);<br>end;<br><br>procedure TForm2.Button2Click(Sender: TObject);<br>begin<br> &nbsp;form1.Show;<br>end;<br><br>end.
 

Similar threads

S
回复
0
查看
831
SUNSTONE的Delphi笔记
S
S
回复
0
查看
788
SUNSTONE的Delphi笔记
S
后退
顶部