4

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

Jeff
  • 12,085
  • 12
  • 82
  • 152

3 Answers3

6

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;
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
karlphillip
  • 92,053
  • 36
  • 243
  • 426
5

try using the GetWindowRect function

var
  lpRect: TRect;
begin
   GetWindowRect(Edit1.Handle,lpRect);  
   ShowMessage(Format('%d,%d',[lpRect.Left,lpRect.Top]));
end;
RRUZ
  • 134,889
  • 20
  • 356
  • 483
1

keep in mind, if the window(app) is minimized, you will get some values for the Rect like these (-32000, -32000, -31840, -31972, (-32000, -32000), (-31840, -31972))

ramses
  • 49
  • 1
  • 11