给出两点,限制鼠标两点组成的线条上移动,是在整个屏幕上面限制而不是在自己程序中限制
由于我很久没有写delphi了,希望能帮我从算法到程序实现都写出来,谢谢
由于我很久没有写delphi了,希望能帮我从算法到程序实现都写出来,谢谢
解决方案 »
- 奇怪!!!SSE2竟然不比MMX快?!!!
- TListBox自画时,如何支持背景和让背景色渐变
- 100再开一帖,求牛人!word的vba----->delphi代码
- 如何修改自己进程里面的UDP数据
- dxGrid,cxGrid有什么不同,个有什么优缺点,欢迎大家来发贴!!!
- 这样的抽奖算法怎么写?
- 关于读取光盘的磁道的问题
- 【紧急求救】动态创建TXMLDocument后,其的DocumentElement不能使用。报Access violation错误!
- delphi 开发服务端 有什么开源的模型吗?
- 菜鸟遇到麻烦!Tquery查询?
- delphi的语句太长想续行怎么做呢,象VB的续行符 _
- 求教一个简单的问题!!
反正一定有clip什么什么的。。-_-
Delphi中使用Windows单元var
rect:TRect;............
rect.left:=?;
rect.top:=?
rect.right:=?
rect.bottom:=?ClipCursor(@rect);如果要取消鼠标位置限制rect.Left ,rect.top,rect.right.rect.bottom都为0;———————————
┏━★━━◆━━★━┓
♂欢|◢CSDN◣|使♂
┃迎|◥论坛助手◤|用┃
┗━☆━━◇━━━☆┛
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type TClipThread = class(TThread)
private
fa : double;
fb : double;
MaxX : integer;
MinX : integer;
MaxY : integer;
MinY : integer;
newp : TPoint;
FBeginP: TPoint;
FEndP: TPoint;
FClip: boolean;
procedure SetClip(const Value: boolean);
public
constructor Create(P1 , P2 : TPoint);
procedure Execute;override;
published
property Clip : boolean read FClip write SetClip;
end; TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
T1 : TClipThread;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
T1 := TClipThread.Create(Point(50,500),Point(500,50));
end;{ TClipThread }constructor TClipThread.Create(P1 , P2 : TPoint);
begin
inherited Create(true);
self.FBeginP := P1;
self.FEndP := P2; if P1.X >= P2.X then
begin
self.MaxX := P1.X ;
self.MinX := p2.X
end
else
begin
self.MaxX := P2.X;
self.MinX := P1.X;
end;
if P1.Y >= P2.Y then
begin
self.MaxY := P1.Y ;
self.MinY := p2.Y
end
else
begin
self.MaxY := P2.Y;
self.MinY := P1.Y;
end;
fb := (P2.X*P1.Y - P1.X*P2.Y) / (P2.X - P1.X);
fa := (P2.Y - P1.Y ) / (P2.X - P1.X);
end;procedure TClipThread.Execute;
begin
inherited;
newp.X := (self.FBeginP.X + self.FEndP.X) div 2;
newp.Y := (self.FBeginP.Y + self.FEndP.Y) div 2;
SetCursorPos(newp.X,newp.Y);
while not self.Terminated do
begin
GetCursorPos(newp);
if newp.X < self.MinX then
newp.X := self.MinX;
if newp.X > self.MaxX then
newp.X := self.MaxX;
if newp.Y < self.MinY then
newp.Y := self.MinY;
if newp.Y > self.MaxY then
newp.Y := self.MaxY; newp.Y := trunc(fa*newp.X + fb);
SetCursorPos(newp.X,newp.Y); end;
end;procedure TClipThread.SetClip(const Value: boolean);
begin
FClip := Value;
if self.FClip then
self.Resume
else
self.Suspend;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
t1.Resume;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
t1.Suspend;
end;end.
使用ClipCursor()函数就可以限制整个屏幕上移动。
我在VC++ 6.0 和Delphi 6.0都可以。———————————
┏━★━━◆━━★━┓
♂欢|◢CSDN◣|使♂
┃迎|◥论坛助手◤|用┃
┗━☆━━◇━━━☆┛
var
rtButton2:TRect;
begin
rtButton2:=button2.BoundsRect;
//MapWindowPoints(handle,0,rtButton2,2);//将button2 的坐标转化为屏幕坐标
ClipCursor(@rtButton2);
end;procedure TForm3.Button2Click(Sender: TObject);
begin
ClipCursor(nil);
end;