鼠标移动到窗体控件中部位置

I

import

Guest
#1
(*// 标题:鼠标移动到窗体控件中部位置
说明:可以使控件焦点和鼠标位置保持一致
设计:Zswang
日期:2002-01-25
支持:wjhu111@21cn.com
//*)
///////Begin Source
function MoveMouseToWindow(mHandle: THandle): Boolean; overload;
{ 返回将鼠标移动到窗体控件中部位置上是否成功 }
var
vRect: TRect;
begin
Result := False;
if not IsWindow(mHandle) then Exit;
GetWindowRect(mHandle, vRect);
Mouse.CursorPos := Point(vRect.Left + (vRect.Right - vRect.Left) div 2,
vRect.Top + (vRect.Bottom - vRect.Top) div 2);
Result := True;
end; { MoveMouseToWindow }
function MoveMouseToWindow(mWinControl: TWinControl): Boolean; overload;
{ 返回将鼠标移动到窗体控件中部位置上是否成功 }
begin
Result := False;
if not Assigned(mWinControl) then Exit;
Result := MoveMouseToWindow(mWinControl.Handle);
end; { MoveMouseToWindow }
///////End Source
///////Begin Demo
procedure TForm1.Timer1Timer(Sender: TObject);
begin
MoveMouseToWindow(ActiveControl);
end;
///////End Demo