如何让一个窗口不被选中(55分)

  • 主题发起人 主题发起人 微风的吻
  • 开始时间 开始时间

微风的吻

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在遇到一个问题需要大家帮忙:<br><br>大家都见过屏保,如果屏保设置了密码,这关闭时会提示你输入密码,<br>而此时密码窗口占据前台,同时后台的屏保线程也在同时执行,只不过<br>无法被选中,我现在就有一个程序要实现这样的功能。后台的窗口中有<br>线程要执行,但不能被选中,我尝试了用showmodal来显示前台窗体让<br>后台窗口不被选中,但这样前台的窗体会独占线程而是后台窗体重的线<br>程停止执行了,只有前台窗体关闭后,后台线程才会继续执行,这不是<br>我想要的结果,不知有没有什么好办法解决,请多指教。
 
你也用多线程
 
不被选中?ENABLED:=FALSE不行吗?
 
回xWolf:TopMost对我这种情况不管用,因为我的主要目的是让后台<br>&nbsp; &nbsp; &nbsp; &nbsp; 的窗口在最后端,前台的窗口有很多,总不能全部都TopMost吧??<br><br>回crystal:如果设置Enabled:=False就会让窗口中的线程停止执行,所以<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 不行.<br>回xueminliu:还请多指教.
 
<br>tmp:=0; { var integer }<br>SystemParametersInfo( SPI_SETFASTTASKSWITCH, 1, @tmp, 0);<br>SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, @tmp, 0);<br>连 Ctrl+Alt+Del 都关不掉的
 
截下消息(wm_activeapp什么什么的),不做处理即可
 
经常有人想些怪东西。
 
这是我的想法,没试过,不知行不行的:<br>在当前窗口中检测鼠标按下(注意,不是单击)和键盘的事件,如果鼠标按下时指针不是在<br>当前窗口的位置里就不响应(或者如果鼠标按下时所指的窗口是你那个后台窗口就返回前台<br>窗口),然后键盘吗,如果是像屏保那样的就可以用OopsWare说的方法去做。不知行不行,<br>只是一个想法而已!
 
我觉得还是用多线程比较好!
 
试试下面这个:<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TPainterThread = class(TThread)<br>&nbsp; private<br>&nbsp; &nbsp; X, Y: Integer;<br>&nbsp; protected<br>&nbsp; &nbsp; procedure Execute; override;<br>&nbsp; &nbsp; procedure Paint;<br>&nbsp; end;<br><br>type<br>&nbsp; TForm1 = 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; &nbsp; procedure FormMouseDown(Sender: TObject; Button: TMouseButton;<br>&nbsp; &nbsp; &nbsp; Shift: TShiftState; X, Y: Integer);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; PT: TPainterThread;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>{ TPainterThread }<br><br>procedure TPainterThread.Execute;<br>begin<br>&nbsp; Randomize;<br>&nbsp; repeat<br>&nbsp; &nbsp; X := Random (300);<br>&nbsp; &nbsp; Y := Random (Form1.ClientHeight);<br>&nbsp; &nbsp; Synchronize (Paint);<br>&nbsp; until Terminated;<br>end;<br>procedure TPainterThread.Paint;<br>begin<br>&nbsp; Form1.Canvas.Pixels [X, Y] := clRed;<br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; Button1.Enabled := False;<br>&nbsp; Button2.Enabled := True;<br>&nbsp; PT := TPainterThread.Create (False); &nbsp;// 开始<br>end;<br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; PT.Free;<br>&nbsp; Button1.Enabled := True;<br>&nbsp; Button2.Enabled := False;<br>end;<br>procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;<br>&nbsp; Shift: TShiftState; X, Y: Integer);<br>begin<br>&nbsp; ShowMessage('Test');<br>end;<br>end.
 
FORM.ENABLED=FALSE<br>&nbsp;是否更简单?
 
在它上面覆盖一个ENABLED:=FALSE的窗体,可以让这个窗体透明
 
可以实现。<br>这不是窗口能否被选中的问题。<br>主窗口中用 TTimer 控制动画,这时把一个子窗口 ShowModal,动画依然有效。例如:<br>&nbsp; TForm1.Timer1OnTimer<br>&nbsp; begin<br>&nbsp; &nbsp; Label1.Top := Label1.Top + 1;<br>&nbsp; end;<br>&nbsp; TForm1.Button1Click<br>&nbsp; begin<br>&nbsp; &nbsp; Form2.ShowModal; &nbsp; &nbsp;<br>&nbsp; end;<br>Form1 的 Timer1 作用是把 Label1 慢慢下移,按下 Button1 后,Form2 被 ShowModal,<br>但是 Label1 仍然在动。<br>&nbsp; OK ?<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; From: BaKuBaKu<br>
 
接受答案了.
 
后退
顶部