怎么获取程序外窗口的X,Y值(15分)

  • 主题发起人 主题发起人 暗夜中独舞
  • 开始时间 开始时间

暗夜中独舞

Unregistered / Unconfirmed
GUEST, unregistred user!
我想写一个程序,一直监控着系统,每当开起一个新的窗口的时候就可以检测到新的窗口的坐标值,该怎么实现呢????
 
能得到窗口句柄就好办了
 
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, ExtCtrls, StdCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Memo1: TMemo;<br> &nbsp; &nbsp;Timer1: TTimer;<br> &nbsp; &nbsp;procedure Timer1Timer(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br> &nbsp;TopHwnd: Hwnd;<br> &nbsp;Rect: TRect;<br>begin<br> &nbsp;TopHwnd := Windows.GetForegroundWindow;<br> &nbsp;Windows.GetWindowRect(TopHwnd, Rect);<br> &nbsp;Memo1.Lines.Add(<br> &nbsp; &nbsp; &nbsp; &nbsp; Format('TopHwnd: %2.2xH, Left: %d, Top: %d, Width: %d, Heigth: %d', [<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TopHwnd, Rect.Left, Rect.Top, Rect.Right - Rect.Left, Rect.Bottom - Rect.Top ]));<br><br>end;<br><br>end.
 
timer不保险,肯定要利用消息机制,不过我对消息不太懂行
 
findwindow找到窗口句柄就很好办了
 
后退
顶部