限制鼠标活动范围???(29分)

  • 主题发起人 主题发起人 bitgege
  • 开始时间 开始时间
B

bitgege

Unregistered / Unconfirmed
GUEST, unregistred user!
想让鼠标限制在登录窗口里活动??<br>我写的代码:<br>procedure TForm2.FormCreate(Sender: TObject);<br>var<br>&nbsp; logFrmRect:TRect;<br>begin<br>&nbsp; &nbsp;GetWindowRect(handle,logFrmRect);<br>&nbsp; &nbsp;ClipCursor(@logFrmRect);<br>end;<br><br>end.<br>可是一点反应都没有,根本就没有限制!!<br>鼠标仍然可以随便移动??<br>问题出在哪里??<br>
 
procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; rtButton2: TRect;<br>begin<br>&nbsp; rtButton2 := Button2.BoundsRect;<br>&nbsp; MapWindowPoints(handle, 0, rtButton2, 2); // 座标换算<br>&nbsp; ClipCursor(@rtButton2); // 限制鼠标移动区域<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br>&nbsp; rtScreen: TRect;<br>begin<br>&nbsp; rtScreen := Rect(0, 0, Screen.Width, Screen.Height);<br>&nbsp; ClipCursor(@rtScreen);<br>end;<br><br>
 
我是说窗体,而不是按钮??
 
将同样的代码放在了application的onidle事件中就解决<br>这个问题了
 
procedure TForm1.FormActivate(Sender: TObject);<br>var<br>&nbsp;rt: TRect;<br>begin<br>&nbsp; rt:=self.BoundsRect;<br>&nbsp; ClipCursor(@rt); <br>end;
 
hongwei是对的
 
不行啊??<br>我首先定一个了过程:<br>procedure clipFrm();<br>procedure TForm2.clipFrm;<br>var<br>&nbsp; logFrm:TRect;<br>begin<br>&nbsp; &nbsp;GetWindowRect(handle,logFrm);<br>&nbsp; &nbsp;ClipCursor(@logFrm);<br>end;<br>然后:<br>procedure TForm2.FormCreate(Sender: TObject);<br>begin<br>&nbsp; &nbsp;application.onidle:=clipFrm;<br>end;<br>出错!!!
 
到底怎么限制书标在窗体范围移动??<br>各位我是说在窗体,而不是指某个按钮??
 
拜托!!<br>看我上面的,在窗体的OnActivate事件里写<br>我试过的
 
procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; MyRect: TRect;<br>begin<br>&nbsp; MyRect := Form1.GetClientRect; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//得到窗体范围<br>&nbsp; MapWindowPoints(handle, 0, MyRect, 2); &nbsp;// 座标换算<br>&nbsp; ClipCursor(@MyRect); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 限制鼠标移动区域<br>end;<br>
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
602
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
433
import
I
后退
顶部