我的代码,可以完成楼主所说的功能,请大家多多指教!<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Edit1: TEdit;<br> ListBox1: TListBox;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> Sti: TStartupInfo;<br> Psi: TProcessInformation;<br> ThrdId: Cardinal;<br> function EnumProc(Handle: THandle; Param: Integer): Boolean; stdcall;<br> var<br> ClsName: String;<br> WndCapt: String;<br> begin<br> SetLength(ClsName, 250);<br> SetLength(WndCapt, 250);<br> GetWindowText(Handle, PChar(WndCapt), 250);<br> GetClassName(Handle, PChar(ClsName), 250);<br> TStrings(Param).Add('Handle: $' + IntToHex(Handle, 8) + ' ' +<br> PChar(ClsName) + ':' + PChar(WndCapt));<br> Result := True;<br> end;<br>begin<br> ListBox1.Items.Clear;<br> FillMemory(@Sti, SizeOf(Sti), 0);<br> Sti.cb := SizeOf(Sti);<br> Sti.wShowWindow := SW_MINIMIZE; //SW_SHOW;<br> Sti.dwFlags := STARTF_USESHOWWINDOW or STARTF_USEFILLATTRIBUTE;<br> Sti.dwFillAttribute := FOREGROUND_INTENSITY or BACKGROUND_BLUE;<br> if CreateProcess(PChar(Edit1.Text), nil,<br> nil, nil, False,<br> 0, nil, PChar(ExtractFilePath(Edit1.Text)),<br> Sti, Psi) then<br> begin<br> ListBox1.Items.Add('Start Process: ' + Edit1.Text);<br> ListBox1.Items.Add('');<br> ThrdId := Psi.dwThreadId;<br> //等待程序启动完毕,最多等待10秒钟,<br> //如果不等待,有可能窗口还没有来得及创建呢<br> WaitForInputIdle(Psi.hProcess, 10*1000);<br> EnumThreadWindows(ThrdId, @EnumProc, Integer(ListBox1.Items));<br> end;<br>end;<br><br>end.<br>