Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Finde Window (https://www.delphipraxis.net/90392-finde-window.html)

ljmarkus 16. Apr 2007 19:37


Finde Window
 
Hallo.

Mein Problem ist, möchte die Position eines Fenster finden und die X und Y Position erkennen um dann in dem Fenster die richtige Position zu bekommen.

Folgender Code gibt mir die Farbwerte aus und die Position auf dem gesamten Bildschirm.


Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
var DC : HDC;
    AColor : Array[1..4] of Byte;
    hwnd_hpc, hwnd_dc: THandle;

begin
  hwnd_hpc := FindWindow('XXXX','XXXX');
  hwnd_dc := GetWindowDC(hwnd_hpc);
  DC:=CreateDC('DISPLAY',NIL,NIL,NIL);
  DWord(AColor) := GetPixel(DC,Mouse.CursorPos.X,Mouse.CursorPos.Y);
  DeleteDC(DC);
  Label1.Caption := 'R: ' + IntToStr(AColor[1]) + ';     ' +
                    'G: ' + IntToStr(AColor[2]) + ';     ' +
                    'B: ' + IntToStr(AColor[3]) + ';     ' +
                    'Hex: ' + IntToHex(DWord(AColor),6);

  Label4.Caption := 'TColor: $'+IntToHex(DWord(AColor),8);

  Label2.Caption := 'X: ' + IntToStr(Mouse.CursorPos.X);
  Label3.Caption := 'Y: ' + IntToStr(Mouse.CursorPos.Y);
end;
Vielen Dank schonmal.

lg, markus

bitsetter 16. Apr 2007 21:42

Re: Finde Window
 
Hallo,

ich weiß nicht ob ich dich richtig verstanden habe, meinst du sowas hier?
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var
  WinInfo: TWindowInfo;
begin
  ZeroMemory(@WinInfo, sizeOf(WinInfo));
  WinInfo.cbSize:= SizeOf(WinInfo);
  GetWindowInfo((*Handle*), WinInfo);
  caption:= inttostr(Mouse.CursorPos.X- WinInfo.rcClient.Left)+ '  '+ inttostr(Mouse.CursorPos.Y- WinInfo.rcClient.Top);
end;
Es gibt aber noch andere Möglichkeiten, diese hier ist mir gerade eingefallen.

EDIT: Geht das bei dir nicht auch mit
Delphi-Quellcode:
windows.GetDC(0)
? Dann hast du doch den DC vom Desktop.

ljmarkus 16. Apr 2007 21:53

Re: Finde Window
 
Hallo.

Ich habe das jetzt so gelöst:

Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
var DC : HDC;
    AColor : Array[1..4] of Byte;
    TheWindowHandle: THandle;
    aRect: TRect;
    ergebnisX, ergebnisY : integer;
begin

  DC:=CreateDC('DISPLAY',NIL,NIL,NIL);

  DWord(AColor) := GetPixel(dc,Mouse.CursorPos.X,Mouse.CursorPos.Y);
  DeleteDC(dc);

  Label1.Caption := 'R: ' + IntToStr(AColor[1]) + ';     ' +
                    'G: ' + IntToStr(AColor[2]) + ';     ' +
                    'B: ' + IntToStr(AColor[3]) + ';     ' +
                    'Hex: ' + IntToHex(DWord(AColor),6);

  Label4.Caption := 'TColor: $'+IntToHex(DWord(AColor),8);

  Label2.Caption := 'X: ' + IntToStr(Mouse.CursorPos.X);
  Label3.Caption := 'Y: ' + IntToStr(Mouse.CursorPos.Y);



  TheWindowHandle := FindWindow('xxxxx','xxxxx');
  GetWindowRect(TheWindowHandle, ARect);
  label5.Caption := 'X: '+ IntToStr(aRect.Left);
  label6.Caption := 'Y: '+ IntToStr(aRect.Top);

  ergebnisX := Mouse.CursorPos.X - aRect.Left;
  label7.Caption := 'X: ' + IntToStr(ergebnisX);

  ergebnisY := Mouse.CursorPos.Y - aRect.Top;
  label8.Caption := 'Y: ' + IntToStr(ergebnisY);

end;
lg, markus


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:27 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 by Thomas Breitkreuz