樓上貼原理, 我只能貼代碼了<br><br> function ExecuteEnumProc(hWin : HWND; lParam : LPARAM) : boolean; stdcall;<br> begin<br> Result := True;<br> if (IsWindowVisible(hWin)) AND (GetParent(hWin) = 0) AND<br>(GetWindow(hWin, GW_OWNER) = 0) then begin<br> pHWND(lParam)^ := hWin;<br> Result := False;<br> end;<br> end;<br> <br> function Execute(const CommandLine : string; const InitializationTimeout<br>: cardinal; const Init_Fudge : cardinal = EXEC_INIT_FUDGE) : HWND;<br> var<br> tSI : TStartupInfo;<br> tPI : TProcessInformation;<br> dwI : DWORD;<br> begin<br> FillChar(tSI, SizeOf(TStartupInfo), 0);<br> tSI.cb := sizeof(TStartupInfo);<br> Result := 0;<br> if (CreateProcess(nil, pchar(CommandLine), nil, nil, False, 0, nil,<br>nil, tSI, tPI)) then begin<br> dwI := WaitForInputIdle(tPI.hProcess, InitializationTimeout); //<br>Not using dwI<br> Sleep(Init_Fudge);<br> EnumThreadWindows(tPI.dwThreadId, @ExecuteEnumProc,<br>LPARAM(@Result));<br> CloseHandle(tPI.hProcess);<br> CloseHandle(tPI.hThread);<br> end;<br> end;<br>