Einzelnen Beitrag anzeigen

Benutzerbild von Sprint
Sprint

Registriert seit: 18. Aug 2004
Ort: Edewecht
712 Beiträge
 
Delphi 5 Professional
 
#5

Re: Process starten und handle bekommen

  Alt 8. Nov 2004, 12:36
Zitat von perle:
wie kann ich denn über an das Handle des Fensters gelangen (auch wenns SW_HIDE ist)?
Ich hab das jetzt mal mit NODEPAD.EXE und EnumWindows ausprobiert. Scheint so, als wenn das bei mir funktionieren würde.
Delphi-Quellcode:
function RunProcess(const FileName: String): HWND;

  function EnumWindowsProc(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
  begin
    TList(lParam).Add(Pointer(hWnd));
    Result := True;
  end;

var
  SI: TStartupInfo;
  PI: TProcessInformation;
  List: TList;
  ProcessId: DWORD;
  I: Integer;
begin

  Result := 0;
  List := TList.Create;
  try
    FillChar(SI, SizeOf(TStartupInfo), 0);
    SI.cb := SizeOf(TStartupInfo);
    // SI.dwFlags := STARTF_USESHOWWINDOW;
    // SI.wShowWindow := SW_HIDE;
    if CreateProcess(nil, PChar(FileName), nil, nil, False, 0, nil, nil, SI, PI) then
    begin
      WaitForInputIdle(PI.hProcess, INFINITE);
      if EnumWindows(@EnumWindowsProc, Longint(List)) then
      begin
        for I := 0 to List.Count - 1 do
        begin
          GetWindowThreadProcessId(Longint(List.Items[I]), ProcessId);
          if PI.dwProcessId = ProcessId then
          begin
            Result := Longint(List.Items[I]);
            Break;
          end;
        end;
      end;
      CloseHandle(PI.hProcess);
      CloseHandle(PI.hThread);
    end;
  finally
    List.Free;
  end;

end;

Edit: Funktioniert bei mir einwandfrei.
Ciao, Sprint.

"I don't know what I am doing, but I am sure I am having fun!"
  Mit Zitat antworten Zitat