开发者

Finding external Window's position?

开发者 https://www.devze.com 2023-02-28 07:45 出处:网络
How can I find the Screen-relative position of a Windo开发者_如何学运维w Handle in Delphi? (X,Y)Use FindWindow() to retrieve the handle of the window and and GetWindowRect() to get the coordinates:

How can I find the Screen-relative position of a Windo开发者_如何学运维w Handle in Delphi? (X,Y)


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;


try using the GetWindowRect function

var
  lpRect: TRect;
begin
   GetWindowRect(Edit1.Handle,lpRect);  
   ShowMessage(Format('%d,%d',[lpRect.Left,lpRect.Top]));
end;


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))

0

精彩评论

暂无评论...
验证码 换一张
取 消