先贴一段lichengbin大虾的代码,用EnumChildWindows和WindowFromPoint倒是可以获得,不知道为什么spy不行,我是2003的,spy是VC6带的那个,真是奇怪<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, ExtCtrls, StdCtrls, ActnList;<br><br>type<br> TForm1 = class(TForm)<br> LblWndInfo: TLabel;<br> Timer1: TTimer;<br> ActionList1: TActionList;<br> Action1: TAction;<br> Memo1: TMemo;<br> Action2: TAction;<br> procedure Timer1Timer(Sender: TObject);<br> procedure Action1Execute(Sender: TObject);<br> procedure Action2Execute(Sender: TObject);<br> private<br> { Private declarations }<br> FWnd: HWND;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>uses Clipbrd;<br><br>{$R *.dfm}<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br> P: TPoint;<br> Wnd: HWND;<br> buf: array[0..255] of Char;<br> S: string;<br> ThreadID, ProcessID: DWORD;<br>begin<br> GetCursorPos(P);<br> Wnd := WindowFromPoint(P);<br> if Wnd <> FWnd then<br> begin<br> FWnd := Wnd;<br> ThreadID := GetWindowThreadProcessID(FWnd, ProcessID);<br> S := Format('(%.8x-%.8x)%.8x: ', [ProcessID, ThreadID, FWnd]);<br> GetClassName(FWnd, buf, Sizeof(buf));<br> S := S + buf;<br> SendMessage(FWnd, WM_GETTEXT, Sizeof(buf), Longint(@buf));<br> S := S + ', ' + buf;<br><br> Wnd := GetParent(Wnd);<br> if Wnd <> 0 then<br> begin<br> GetClassName(Wnd, buf, Sizeof(buf));<br> S := S + Format('(Parent: %.8x, %s)', [Wnd, string(buf)]);<br> end;<br> LblWndInfo.Caption := S;<br> if Width < LblWndInfo.Width + 24 then<br> Width := LblWndInfo.Width + 24;<br> end;<br>end;<br><br>procedure TForm1.Action1Execute(Sender: TObject);<br>begin<br> Clipboard.AsText := LblWndInfo.Caption;<br>end;<br><br>function EnumChildProc(hwnd: HWND; lParam: LPARAM): BOOL; stdcall;<br>var<br> S1, S2: array[0..255] of Char;<br> hwndParent: THandle;<br>begin<br> hwndParent := GetParent(hwnd);<br> GetClassName(hwnd, S1, 255);<br> SendMessage(hwnd, WM_GETTEXT, 255, Integer(@S2));<br> Form1.Memo1.Lines.Add(Format('hwnd: %.8x Parent: %.8x ClassName: %s Caption: %s', [hwnd, hwndParent, S1, S2]));<br> Result := True;<br>end;<br><br>procedure TForm1.Action2Execute(Sender: TObject);<br>begin<br> EnumChildWindows(FWnd, @EnumChildProc, 0);<br>end;<br><br>end.