unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;<br><br>type<br> EnumThreadWndProc=function(hw:HWND;lP:LPARAM):boolean;<br><br>type<br> TForm1 = class(TForm)<br> ListBox1: TListBox;<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure ListBox1DblClick(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br> function Enum(hw:HWND;lP:LPARAM):boolean;stdcall;<br><br>var<br> Form1: TForm1;<br> st:TStartUpInfo;<br> pp:array[1..3] of TProcessInformation;<br> ppp:Thandle;<br><br>implementation<br><br>{$R *.DFM}<br><br>function Enum(hw:HWND;lP:LPARAM):boolean;<br>var<br> Buffer:Array[0..255] of Char;<br>begin<br> if GetTopWindow(hw)<>0 then<br> begin<br> GetWindowText(hw,buffer,256);<br> TListBox(lp).items.addobject(buffer,Tobject(hw));<br> end;<br> Result:=true;<br>end;<br><br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> proc:EnumThreadWndProc;<br> i:integer;<br>begin<br> proc:=@Enum;<br>for i:=1 to 2 do<br> EnumThreadWindows(pp.dwThreadId,@proc,lparam(listbox1));<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>FillChar(st,sizeof(st),#0);<br>with st do<br>begin<br> cb:=sizeof(st);<br> dwFlags:=StartF_UsesTDHandles or STARTF_USESHOWWINDOW;<br> lptitle:=nil;<br> wShowWindow:=SW_HIDE;<br>end;<br>CreateProcess(PChar('c:/program files/microsoft office/office/winword.exe'),<br> nil,nil,nil,true,DETACHED_PROCESS,nil,nil,st,pp[1]);<br>CreateProcess(PChar('c:/program files/microsoft office/office/Excel.exe'),<br> nil,nil,nil,true,DETACHED_PROCESS,nil,nil,st,pp[2]);<br>end;<br><br>procedure TForm1.ListBox1DblClick(Sender: TObject);<br>begin<br> ppp:=Thandle(Listbox1.Items.Objects[Listbox1.ItemIndex]);<br> if IsWindowVisible(ppp) then<br> BringWindowToTop(ppp)<br> else<br> showwindow(ppp,sw_show);<br>end;<br><br>end.<br>