function WindowHasChild(H: HWND): boolean; //判断有无子窗口<br>var M: HWND;<br>begin<br> M:=GetWindow(H,GW_CHILD);<br> if M=0 then<br> result:=false<br> else<br> result:=true;<br>end;<br><br>procedure CreateTree(H: HWND; T: TTreeNode);<br>var M: HWND;<br> P: PChar;<br> s: string;<br> s1: string;<br> N: TTreeNode;<br>begin<br> M:=GetWindow(H,GW_CHILD);<br> while M<>0 do<br> begin<br> GetMem(P,256);<br> GetClassName(M,P,256);<br> s:='ClassName='+strpas(P);<br> GetWindowText(M,P,256);<br> s1:=strpas(P);<br> if s1='' then<br> s1:='Nil';<br> s:=s+' Caption='+s1+' Handle='+IntToSTr(M);<br> N:=Form1.TreeView1.Items.AddChild(T,s);<br> Freemem(P);<br> if WindowHasChild(M) then<br> CreateTree(M,N); 递归调用<br> end;<br> M:=GetWindow(M,GW_HWNDNEXT);<br>end;<br><br>var x: TTreeNode;<br> TreeView1.Items.Clear;<br> x:=TreeView1.Items.Add(nil,s);<br> CreateTree(GetDesktopWindow(),x); //用树型结构表示当前拥有句柄窗口的<br> 结构,有了层次结构和句柄什么API不可<br> 调用<br> <br>