![]() |
Mouseposition innerhalb des Forms bestimmen
Ich würde gerne die Mausposition innerhalb meines Programms bestimmen und setzen.(d.h., dass der erste Pixel meins Forms auch gleichzeitig Mouse.Position X/Y = 1/1 ist)
Außerdem möchte ich dasselbe mit einem gerade laufenden Programm machen. Möglich? :dp: |
Re: Mouseposition innerhalb des Forms bestimmen
Wenn du das Handle des fremden Fensters kennst, müsste folgendes funktionieren.
Delphi-Quellcode:
Ich hoffe mal, du meintest es auch so.
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; |
Re: Mouseposition innerhalb des Forms bestimmen
Zitat:
|
Re: Mouseposition innerhalb des Forms bestimmen
Suche mal nach folgenden Begriffen:
FindWindow EnumWindows WindowFromPoint Oder du kannst das Handle auch mit einem Programm herausfinden z.B. xSpy: ![]() |
Re: Mouseposition innerhalb des Forms bestimmen
Ist es möglich dasselbe wie im Code dort oben nur statt mit dem Hanle mit dem WindowsCaption zu machen?
|
Re: Mouseposition innerhalb des Forms bestimmen
Jop, indem du das Handle mithilfe von Findwindow rausfindest.
|
Re: Mouseposition innerhalb des Forms bestimmen
Zitat:
|
Re: Mouseposition innerhalb des Forms bestimmen
Das mit der Mausposition geht sehr gut, nur leider krieg ich es nicht hin das übers Netzwerk zu übertragen.
So hab ichs gemacht: Server:
Delphi-Quellcode:
Client:
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.Server2Execute(AThread: TIdPeerThread); var mp: TPoint; begin mp:= getpos(Form1.Handle); with Athread.Connection do begin WriteInteger(mp.x); WriteInteger(mp.y); Disconnect; end; end;
Delphi-Quellcode:
Das Problem ist, das es keine Message anzeigt und auch nicht die Mausposition verändert. (Ich kriege aber auch keine Fehler)
with Client2 do
begin Connect; try xy.X := ReadInteger(true); xy.Y := ReadInteger(true); finally Disconnect; end; SetPos(Han,xy); ShowMEssage(strtoint(xy.X)+'/'+strtoint(xy.y)); 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; |
Re: Mouseposition innerhalb des Forms bestimmen
Inzwischen gibt er mir eine Message aus, aber leider nur eine bei der X= 1 ist und Y irgendeine sechsstellige Zahl.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:17 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz