Delphi如何获取其他程序窗体Left和Top

来源:百度知道 编辑:UC知道 时间:2024/05/10 14:26:47
如何获取一个正在运行的程序他的窗体在屏幕中的left和top值?
我要获取的是另一个程序,不是自身

先用FindWindow查找到程序的窗口句柄,之后用GetWindowRect窗口的边框矩形,就可以啦!例如

procedure TForm1.Button1Click(Sender: TObject);
var
hwn :THandle;
r :TRect;
begin
hwn := FindWindow('CabinetWClass','我的电脑);//XP的是'我的电脑',vista是'计算机'
if hwn <> 0 then
begin
GetWindowRect(hwn,r);
showmessage(inttostr(r.Left));
showmessage(inttostr(r.Top));
end;
end;

比如要用 form2
在implenention下边
添加 uses unit2.pas;
然后 写 form2.left就 好用 了