Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding external Window's position?

How can I find the Screen-relative position of a Window Handle in Delphi? (X,Y)

like image 375
Jeff Avatar asked Dec 16 '22 14:12

Jeff


2 Answers

Use FindWindow() to retrieve the handle of the window and and GetWindowRect() to get the coordinates:

var 
 NotepadHandle: hwnd;
 WindowRect: TRect;
begin
 NotepadHandle := FindWindow(nil, 'Untitled - Notepad');

 if NotepadHandle <> 0 then
   GetWindowRect(NotepadHandle, WindowRect)

end;
like image 112
karlphillip Avatar answered Jan 02 '23 19:01

karlphillip


try using the GetWindowRect function

var
  lpRect: TRect;
begin
   GetWindowRect(Edit1.Handle,lpRect);  
   ShowMessage(Format('%d,%d',[lpRect.Left,lpRect.Top]));
end;
like image 43
RRUZ Avatar answered Jan 02 '23 19:01

RRUZ