-1

Using the CreateProcess function from Winapi.Windows unit, I am opening an executable from another but when it opens it doesn't display it on top of the executable that's calling it.

Here is the procedure that I put together:

procedure Tfrm1.ExecuteProg(Cmdl: String; Pause: Boolean);
var SI : TStartUpInfo;
    PI: TProcessInformation;
begin
 FillChar(SI, Sizeof(SI), 0);

 with SI do
 begin
  cb := SizeOf(TStartUpInfo);
  dwFlags := StartF_UseShowWindow;
  wShowwindow := SW_SHOWNORMAL;
 end;

 if (CreateProcess(nil, PChar(Cmdl), nil, nil, False, 0, nil, nil, SI, PI)) then
  if Pause then WaitForInputIdle(PI.hProcess, INFINITE);
end;

Is there something else that I need to be doing?

Any help would be great, thanks.

6String_Coder
  • 517
  • 10
  • 30

1 Answers1

-1

After the above procedure is called I did the following :

WinHandle := FindWindow(nil, WindowName);

if WinHandle <> null
  then SetForegroundWindow(WinHandle);
6String_Coder
  • 517
  • 10
  • 30
  • Should not be needed. As I said above, the behaviour you describe cannot be reproduced with a simple empty app. Clearly something else is happening in your scenario that we cannot see. If you would do as I said, and make a [mcve], then this would be a viable question. – David Heffernan Jun 22 '17 at 10:52
  • Hi David, thank you for your input, for now this will be a temporary fix, the project that I'm working on has a lot of code in it and will take time to step through to try and identify the issue, it was originally done in XE3 and this issue never happened then, having brought the project up to date and converted to a later version - 10.1 berlin - this is when I noticed it happening, Il contribute more info to this question if I find out what the cause is, thanks again :) – 6String_Coder Jun 22 '17 at 11:12
  • If you don't feel compelled to understand this then you should remove the entire post. – David Heffernan Jun 22 '17 at 11:16