根据进程句柄,不能列举进程的窗口!!<br>根据进程ID列举进程所有窗口句柄的方法:用CreateToolhelp32Snapshot列举系统线程(一个进程有多个线程);对每个线程,如果其进程ID=规定的进程ID,则用EnumThreadWindows等列举线程窗口。<br>下面的程序运行结果与spyxx对照过,完全正确。<br>==============================<br>根据进程ID列举进程所有窗口句柄<br>==============================<br>unit Unit1;<br>interface<br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls, TLHelp32;<br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> ListBox1: TListBox;<br> Edit1: TEdit;<br> procedure Button1Click(Sender: TObject);<br> procedure MyENumChildWindows(h: HWND);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br>var<br> Form1: TForm1;<br>implementation<br>{$R *.DFM}<br>procedure TForm1.MyENumChildWindows(h: HWND);<br>var<br> h1: HWND;<br>begin<br> h1:=GetWindow(h,GW_CHILD);<br> While(h1&gt;0) do<br> begin<br> ListBox1.Items.Add(IntToHex(h1,8));<br> if GetWindow(h1,GW_CHILD)&gt;0 then MyENumChildWindows(h1);<br> h1:=GetWindow(h1,GW_HWNDNEXT);<br> end;<br>end;<br><br>function WNDENUMPROC(h: HWND; l: lParam): bool; StdCall;<br>begin<br> Form1.ListBox1.Items.Add(IntToHex(h,8));<br> Form1.MyENumChildWindows(h);<br> result:=true;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> Lpte: TThreadEntry32;<br> Found: boolean;<br> Handle: THandle;<br>begin<br> Handle:=CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);<br> lpte.dwSize:=Sizeof(TThreadEntry32);<br> Found:=Thread32First(Handle,Lpte);<br> while Found do<br> begin<br> //如果线程的进程ID=规定的进程ID<br> if Lpte.th32OwnerProcessID=strtoint(edit1.text) then<br> begin<br> EnumThreadWindows(Lpte.th32ThreadID,@WNDENUMPROC,0);<br> end;<br> Found:=Thread32Next(Handle,Lpte);<br> end;<br> CloseHandle(Handle);<br>end;<br><br>end.