windows 寻找外部窗口的位置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5778703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:43:09  来源:igfitidea点击:

Finding external Window's position?

windowsdelphiwindow-handles

提问by Jeff

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

如何在 Delphi 中找到窗口句柄的屏幕相对位置?(X,Y)

回答by RRUZ

try using the GetWindowRectfunction

尝试使用该GetWindowRect功能

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

回答by karlphillip

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

使用 FindWindow() 检索窗口句柄并使用 GetWindowRect() 获得坐标:

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

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

end;

回答by ramses

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

请记住,如果窗口(应用程序)被最小化,您将获得 Rect 的一些值,如下所示 (-32000, -32000, -31840, -31972, (-32000, -32000), (-31840, -31972))