AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Mouseposition innerhalb des Forms bestimmen
Thema durchsuchen
Ansicht
Themen-Optionen

Mouseposition innerhalb des Forms bestimmen

Offene Frage von "skyquaker"
Ein Thema von skyquaker · begonnen am 8. Feb 2007 · letzter Beitrag vom 10. Feb 2007
Antwort Antwort
skyquaker

Registriert seit: 14. Sep 2006
96 Beiträge
 
Delphi 7 Professional
 
#1

Mouseposition innerhalb des Forms bestimmen

  Alt 8. Feb 2007, 14:32
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?

  Mit Zitat antworten Zitat
Benutzerbild von bitsetter
bitsetter

Registriert seit: 17. Jan 2007
1.169 Beiträge
 
Turbo Delphi für Win32
 
#2

Re: Mouseposition innerhalb des Forms bestimmen

  Alt 8. Feb 2007, 18:00
Wenn du das Handle des fremden Fensters kennst, müsste folgendes funktionieren.
Delphi-Quellcode:
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;
Ich hoffe mal, du meintest es auch so.
Gruß bitsetter
"Viele Wege führen nach Rom"
Wolfgang Mocker (geb. 1954), dt. Satiriker und Aphoristiker
  Mit Zitat antworten Zitat
skyquaker

Registriert seit: 14. Sep 2006
96 Beiträge
 
Delphi 7 Professional
 
#3

Re: Mouseposition innerhalb des Forms bestimmen

  Alt 8. Feb 2007, 18:19
Zitat von bitsetter:
Wenn du das Handle des fremden Fensters kennst, müsste folgendes funktionieren.
Delphi-Quellcode:
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;
Ich hoffe mal, du meintest es auch so.
Ja, das sieht stark nach dem aus, was ich suche. Kann mir jemand sagen, wie ich das Hangle des Fensters auslese?
  Mit Zitat antworten Zitat
Benutzerbild von bitsetter
bitsetter

Registriert seit: 17. Jan 2007
1.169 Beiträge
 
Turbo Delphi für Win32
 
#4

Re: Mouseposition innerhalb des Forms bestimmen

  Alt 8. Feb 2007, 18:58
Suche mal nach folgenden Begriffen:
FindWindow
EnumWindows
WindowFromPoint


Oder du kannst das Handle auch mit einem Programm herausfinden z.B. xSpy:
http://www.x-spy.net
Gruß bitsetter
"Viele Wege führen nach Rom"
Wolfgang Mocker (geb. 1954), dt. Satiriker und Aphoristiker
  Mit Zitat antworten Zitat
skyquaker

Registriert seit: 14. Sep 2006
96 Beiträge
 
Delphi 7 Professional
 
#5

Re: Mouseposition innerhalb des Forms bestimmen

  Alt 9. Feb 2007, 17:15
Ist es möglich dasselbe wie im Code dort oben nur statt mit dem Hanle mit dem WindowsCaption zu machen?
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#6

Re: Mouseposition innerhalb des Forms bestimmen

  Alt 9. Feb 2007, 17:19
Jop, indem du das Handle mithilfe von Findwindow rausfindest.
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
skyquaker

Registriert seit: 14. Sep 2006
96 Beiträge
 
Delphi 7 Professional
 
#7

Re: Mouseposition innerhalb des Forms bestimmen

  Alt 9. Feb 2007, 17:47
Zitat von DGL-luke:
Jop, indem du das Handle mithilfe von Findwindow rausfindest.
Thx, das habe ich auchgerade rausgefunden.
  Mit Zitat antworten Zitat
skyquaker

Registriert seit: 14. Sep 2006
96 Beiträge
 
Delphi 7 Professional
 
#8

Re: Mouseposition innerhalb des Forms bestimmen

  Alt 10. Feb 2007, 13:23
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:
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;
Client:
Delphi-Quellcode:
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;
Das Problem ist, das es keine Message anzeigt und auch nicht die Mausposition verändert. (Ich kriege aber auch keine Fehler)
  Mit Zitat antworten Zitat
skyquaker

Registriert seit: 14. Sep 2006
96 Beiträge
 
Delphi 7 Professional
 
#9

Re: Mouseposition innerhalb des Forms bestimmen

  Alt 10. Feb 2007, 16:40
Inzwischen gibt er mir eine Message aus, aber leider nur eine bei der X= 1 ist und Y irgendeine sechsstellige Zahl.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:05 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz