1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
function EnumWindowsProc(HWnd: THandle; Sender: TMainForm): BOOL; stdcall;
var
PID: THandle;
begin
GetWindowThreadProcessId(HWnd, PID);
if PID = Sender.FRunning then
begin
Sender.FWindow := HWnd;
Result := False;
end else begin
Result := True;
end;
end;
procedure TMainForm.StartCmd(const Cmd: string);
var
SI : TStartupInfo;
PI : TProcessInformation;
begin
FillChar(SI, SizeOf(SI), 0);
SI.cb := SizeOf(SI);
FillChar(PI, SizeOf(PI), 0);
CreateProcess(nil, PChar(Cmd), nil, nil, False, 0, nil, nil, SI, PI);
FRunning := PI.dwProcessId;
FProcess := PI.hProcess;
EnumWindows(@EnumWindowsProc, Integer(Self));
end; |
Partager