Finding external Window's position?
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))
精彩评论