〖限制鼠标移出的方法不难,但偶最近要限制鼠标进入某个区域,该如何是好?〗例如:
╭═════════════════════════════╮
║ ║
║ A区 ║
║ ╭═══════════════╮ ║
║ ║ ║ ║
║ ║ ║ ║
║ ║ B区 ║ ║
║ ║ ║ ║
║ ╰═══════════════╯ ║
║ ║
║ ║
╰═════════════════════════════╯让Mouse只能在A区而不能进入B区,请不吝赐教。要求:我不是要在我的Form上限制,而是在Screen上限制。
拒绝:“当鼠标移动到某个区域的时候,你就用SetCursorPos来将它移开”的方法。
分不够下次再补!!!在线等候中……
╭═════════════════════════════╮
║ ║
║ A区 ║
║ ╭═══════════════╮ ║
║ ║ ║ ║
║ ║ ║ ║
║ ║ B区 ║ ║
║ ║ ║ ║
║ ╰═══════════════╯ ║
║ ║
║ ║
╰═════════════════════════════╯让Mouse只能在A区而不能进入B区,请不吝赐教。要求:我不是要在我的Form上限制,而是在Screen上限制。
拒绝:“当鼠标移动到某个区域的时候,你就用SetCursorPos来将它移开”的方法。
分不够下次再补!!!在线等候中……
解决方案 »
- Delphi字符串与浮点数的转换问题
- 关于odac访问oracle的问题
- 出售全新DELPHI 2002-2003中文精华合集(20元)上海的当面交货
- 技术讨论群,欢迎加入!!!
- 郁闷,为什么在SQL SERVER 中定义为DataTime类型字段的表在Delphi中更新记录时出错
- 请问各位一般怎么处理数据库里查询得到的数据,再将处理后的结果呈现给用户?
- 怎样获得当前浏览器的URL?
- IntraWeb编写的程序怎么运行??高分,OnLine Wait!!!
- 在线等待,怎么设置stringgrid每一行的字体大小,怎么使第i行选中
- 在线求助:一个dbgrid的问题,简单,都进来看看吧
- 存储过程的问题?
- Access 2000支持事务吗?我试试,好像可以的。
begin
r := Rect(0,0,20,20);
ClipCursor(@r);
end;
你把屏幕划分为几个距形区域,限制Mouse不能从指定区域出来,不就可以了
这些都是API现成的函数,但是我忘了!呵呵!
。
拒绝:“当鼠标移动到某个区域的时候,你就用SetCursorPos来将它移开”的方法。
请注意CombineRgn不是用来合并Rect的。
我是说你根据B区的位置把A区分成8个,将鼠标限制这8个区域,没叫你合并它们
我知道你的意思啊,你能“将鼠标限制这8个区域”吗?我可不行。
用ClipCursor八次吗?这样只会最后一次起作用,
如果这样就行的话那我的150分不是白花了???
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.
拒绝:“当鼠标移动到某个区域的时候,你就用SetCursorPos来将它移开”的方法。你两个都没符合。我晕……狂晕……
长长长长长长长长长长长长长长长长长长长长长长长长长
我实现了,不过还有一点限制,就是我的程序是当前激活的
用两个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.
procedure TForm1.Button1Click(sender:TObject);
var
rtButton2:TRect;
begin
Rtbutton2:=Button2.BoundsRect;
MapWindowPoints(Handle,0,rtButton2,2);
ClipCurSor(@rtButton2);
end;
我倒,看清题目。
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了!