function GetPos(
Handle: HWND): TPoint;
var
WinInfo: TWindowInfo;
CurPos: TPoint;
begin
Result.X:= -1;
Result.Y:= -1;
FillChar(WinInfo, Sizeof(WinInfo), 0);
WinInfo.cbSize := Sizeof(WinInfo);
GetWindowInfo(
Handle, WinInfo);
GetCursorPos(CurPos);
//if windows.PtInRect(WinInfo.rcWindow, CurPos) then
if windows.PtInRect(WinInfo.rcClient, CurPos)
then
begin
Result.X:= CurPos.X- WinInfo.rcClient.Left;
Result.Y:= CurPos.Y- WinInfo.rcClient.Top;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
CurPos: TPoint;
begin
CurPos:= GetPos(Form1.Handle);
Caption:= '
X: '+inttostr(CurPos.X)+ '
Y: '+inttostr(CurPos.Y);
end;
procedure SetPos(
Handle: HWND; CurPos: TPoint);
var
WinInfo: TWindowInfo;
begin
FillChar(WinInfo, Sizeof(WinInfo), 0);
WinInfo.cbSize := Sizeof(WinInfo);
GetWindowInfo(
Handle, WinInfo);
inc(CurPos.X, WinInfo.rcClient.Left);
//WinInfo.rcWindow.Left
inc(CurPos.Y, WinInfo.rcClient.Top);
//WinInfo.rcWindow.Top
if windows.PtInRect(WinInfo.rcClient, CurPos)
then
setCursorPos(CurPos.X, CurPos.Y);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
CurPos: TPoint;
begin
CurPos.X:= 5;
CurPos.Y:= 15;
SetPos(Form1.Handle, CurPos);
end;