〖限制鼠标移出的方法不难,但偶最近要限制鼠标进入某个区域,该如何是好?〗例如:              
               
  ╭═════════════════════════════╮
  ║                                                      ║
 ║    A区                                               ║
  ║           ╭═══════════════╮           ║
  ║           ║                            ║           ║
  ║           ║                            ║           ║
  ║           ║           B区              ║           ║
  ║           ║                            ║           ║
  ║           ╰═══════════════╯           ║
  ║                                                      ║
 ║                                                      ║
  ╰═════════════════════════════╯让Mouse只能在A区而不能进入B区,请不吝赐教。要求:我不是要在我的Form上限制,而是在Screen上限制。
拒绝:“当鼠标移动到某个区域的时候,你就用SetCursorPos来将它移开”的方法。
分不够下次再补!!!在线等候中……

解决方案 »

  1.   

    var r : TRect;
    begin
      r := Rect(0,0,20,20);
      ClipCursor(@r);
    end;
      

  2.   

    to cslegend():你看看题目再回答好不?是限制进入,不是限制Mouse出来,明白么?
      

  3.   

    GenieWin(精灵太保) 
    你把屏幕划分为几个距形区域,限制Mouse不能从指定区域出来,不就可以了
      

  4.   

    得到鼠标当前点的坐标,如果 IN 你的RECT THEN 把鼠标设置到某一点上;
    这些都是API现成的函数,但是我忘了!呵呵!
      

  5.   

    to l0f(凌风) :

    拒绝:“当鼠标移动到某个区域的时候,你就用SetCursorPos来将它移开”的方法。
      

  6.   

    to cslegend():“你把屏幕划分为几个距形区域,限制Mouse不能从指定区域出来,不就可以了”你试试,能将Rect合并吗?你成功了再贴上来。
      

  7.   

    to cslegend():
    请注意CombineRgn不是用来合并Rect的。
      

  8.   

    GenieWin(精灵太保) 
    我是说你根据B区的位置把A区分成8个,将鼠标限制这8个区域,没叫你合并它们
      

  9.   

    to cslegend():
    我知道你的意思啊,你能“将鼠标限制这8个区域”吗?我可不行。
    用ClipCursor八次吗?这样只会最后一次起作用,
    如果这样就行的话那我的150分不是白花了???
      

  10.   

    设不能进去的区域为Panel1的区域. 
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls;type
      TForm1 = class(TForm)
        Panel1: TPanel;
        procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Integer);
        procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      PrePoint : TPoint;
    implementation{$R *.DFM}procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    var
      CurrentPoint : TPoint;
    begin
      CurrentPoint := ClientToScreen(PrePoint);
      SetCursorPos(CurrentPoint.x,CurrentPoint.y);
    end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      PrePoint.x := x;
      PrePoint.y := y;
    end;end.
      

  11.   

    to Wnyu(西门吹水) :要求:我不是要在我的Form上限制,而是在Screen上限制。
    拒绝:“当鼠标移动到某个区域的时候,你就用SetCursorPos来将它移开”的方法。你两个都没符合。我晕……狂晕……
      

  12.   

    不用SetCursorPos好象不行,帮你顶顶吧.
      

  13.   

    Sorry, 没看清楚,用Hook吧,代码较长.....
    长长长长长长长长长长长长长长长长长长长长长长长长长
      

  14.   

    我也来参加吧!
    我实现了,不过还有一点限制,就是我的程序是当前激活的
    用两个API,getcursorpos  得到当前的鼠标的位置,判断是否已经有你设定的区域内了
    在里面,就用setcursorpos 移出来了原代码如下:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Label1: TLabel;
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
        procedure  myidle(Sender: TObject; var Done: Boolean);
        procedure  mydeca(sender: Tobject);  public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}{ TForm1 }
    var
       norc:Trect;
       isexit:boolean;function  inSize(d:integer;dlow,dhigh:integer):boolean;
    begin
      result:=( d>dlow) and (d<dhigh);
    end;procedure TForm1.myidle(Sender: TObject; var Done: Boolean);
    begin
       mydeca(sender);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
       application.OnIdle:=myidle;
       application.OnDeactivate:=mydeca;
       ondeactivate:=mydeca;
       norc:=rect(100,100,200,200);
    end;procedure TForm1.mydeca(sender: Tobject);
       var p:Tpoint;
    begin
     repeat
      begin
          getcursorpos(p);
          label1.Caption:=format('point(%3d,%3d)',[p.x,p.y]);
          if insize(p.X,norc.Left,norc.Right) and insize(p.Y,norc.Top,norc.Bottom) then
              setcursorpos(norc.Top,norc.Left);
          if isexit then
             exit;
          application.ProcessMessages;
      end
     until not application.active ;
    end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
       isexit:=true;
    end;end.
      

  15.   

    //限制鼠標在button2的范圍內!
    procedure TForm1.Button1Click(sender:TObject);
    var
      rtButton2:TRect;
    begin
    Rtbutton2:=Button2.BoundsRect;
    MapWindowPoints(Handle,0,rtButton2,2);
    ClipCurSor(@rtButton2);
    end;
      

  16.   

    to henry2003(阿波):
        我倒,看清题目。
      

  17.   

    看看关于ClipCursor的说明:
    The ClipCursor function confines the cursor to a rectangular area on the screen. If a subsequent cursor position (set by the SetCursorPos function or the mouse) lies outside the rectangle, Windows automatically adjusts the position to keep the cursor inside the rectangular area. 说明ClipCursor能起到的作用就是截取SetCursorPos这个API函数的调用,所以,如果你不想使用
    SetCursorPos把鼠标设置回来,那就只有HOOK了!