给出两点,限制鼠标两点组成的线条上移动,是在整个屏幕上面限制而不是在自己程序中限制
由于我很久没有写delphi了,希望能帮我从算法到程序实现都写出来,谢谢

解决方案 »

  1.   

    cliprect 手边没任何工具和msdn,好象是这个win32 api吧
    反正一定有clip什么什么的。。-_-
      

  2.   

    应该是ClipCursor()函数。
    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◣|使♂       
    ┃迎|◥论坛助手◤|用┃       
    ┗━☆━━◇━━━☆┛      
      

  3.   

    unit Unit1;interfaceuses
      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.
      

  4.   

    楼上这位朋友的方法太复杂。
    使用ClipCursor()函数就可以限制整个屏幕上移动。
    我在VC++ 6.0 和Delphi 6.0都可以。———————————
    ┏━★━━◆━━★━┓ 
    ♂欢|◢CSDN◣|使♂       
    ┃迎|◥论坛助手◤|用┃       
    ┗━☆━━◇━━━☆┛      
      

  5.   

    procedure TForm3.Button1Click(Sender: TObject);
    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;
      

  6.   

    wdir(wander) 看看你的简单方法,注意是一条线段,不是一个矩形!!!