Controling aplications started with TProcess lazarus / 31-LCL ---------------------------------------------------------------------- seivtcho · 2014-06-10 11:22 My question is can an external software, that was started with TProcess be controlled AFTER its start. I mean, can you minimize and maximize it WHILE it is STILL working, or move it arround the screen without terminating it, or send it in the start line? Eventually can you simulate a pressing of a button of the started software? ---------------------------------------------------------------------- marcov · 2014-06-10 12:25 Not using TProcess itself.  I guess you can get the childs ID or handle from TProcess, and try sending messages using system specific APIs. But there is no uniform API or interface for that. ---------------------------------------------------------------------- engkin · 2014-06-10 14:44 Quote from: seivtcho on June 10, 2014, 01:22:31 pmEventually can you simulate a pressing of a button of the started software? Regardless how that software was started, if you know where the button is then you can use MouseAndKeyInput: Code: [Select]uses ..., MouseAndKeyInput; ...    MouseInput.Move([],x,y);    MouseInput.Down(mbLeft,[]);    MouseInput.Up(mbLeft,[]); ... ---------------------------------------------------------------------- seivtcho · 2014-06-11 16:32 Thanks for the answers! How to get the handle or the ID and to use it? ---------------------------------------------------------------------- Swirl · 2015-12-04 13:08 Hello, I got a similar problem as seivtcho. I know that I simply can get the handle by MyProcess.Handle but I do not know how to use it furthermore. As marcov stated »Not using TProcess itself.« (I believe a guy who contributed more than 4000 posts) I tried a lot of ShowWindow(MyProcess.Handle) but I did not succeed. I simply (pardon) want to to control two other programs from my own application - e.g. prog1/hide/minimize/maximize and prog2/hide/minimize/maximize. Is there a way to achieve this? thx in advance, Swirl ---------------------------------------------------------------------- balazsszekely · 2015-12-04 17:03 @seivtcho, @Swirl QuoteI simply (pardon) want to to control two other programs from my own application - e.g. prog1/hide/minimize/maximize and prog2/hide/minimize/maximize. Is there a way to achieve this?Is there a way to achieve this? It's quite trivial on windows, almost impossible on other platform. For windows: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses Windows, Process; function GetProcessMainWindow(const PID: DWORD; const wFirstHandle: HWND): HWND;var  wHandle: HWND;  ProcID: DWord;begin  Result := 0;  wHandle := GetWindow(wFirstHandle, GW_HWNDFIRST);  while wHandle > 0 do  begin    GetWindowThreadProcessID(wHandle, @ProcID);    if (ProcID = PID) and (GetParent(wHandle) = 0) and (IsWindowVisible(wHandle)) and (IsWindowEnabled(wHandle)) then    begin      Result := wHandle;      Break;    end;    wHandle := GetWindow(wHandle, GW_HWNDNEXT);  end;end; procedure TForm1.Button1Click(Sender: TObject);var  Process: TProcess;  PID: DWord;  wHandle, wChildHandle: THandle;  Str: String;  I: Integer;begin  PID := 0;  Process := TProcess.Create(nil);  try    //Start notepad    Process.Executable := 'notepad.exe';    Process.Execute;    Sleep(1000);    PID := Process.ProcessID;  finally    Process.Free;  end;   if PID <> 0 then  begin    //get notepad main window    wHandle := GetProcessMainWindow(PID, Self.Handle);    if wHandle <> 0 then    begin      FlashWindow(wHandle, True);//just for the fun of it      //do other dirty stuff here, find TButton, TEdit or other child window with FindWindowEx      //in this example we will find notepad's edit window       wChildHandle := FindWindowEx(wHandle, 0, 'Edit', nil);     if wChildHandle <> 0 then       begin         //send some text       Str := 'Lazarus';         for I := 1 to Length(Str) do           PostMessage(wChildHandle, WM_CHAR, Word(Str[I]), 0);       end;       Sleep(3000);      //minimize notepad      ShowWindow(wHandle, SW_MINIMIZE);      Sleep(3000);      //restore      ShowWindow(wHandle, SW_RESTORE);      Sleep(5000);      //kill notepad      PostMessage(wHandle, WM_QUIT, 0, 0);    end;  end;end; ---------------------------------------------------------------------- Swirl · 2015-12-05 16:16 Thx a lot GetMem, I have googled for about one week - no success... Now you solved my problem with 70 lines. I'll keep that nice snippet for further purpose. Have a nice xmas and a happy new year, Swirl