<div dir="ltr">If the other Delphi application isn't correctly responding to <b>SW_SHOWMINNOACTIVE</b> then the problem is in the <b>TApplicaiton</b> code of the version of Delphi involved. The fact that your FormShow event isn't firing suggests that it's an older version of Delphi involved, since an inspection of the <b>TApplication.Run</b> method reveals how this behaviour (or lack of) would eventuate.... <br>
<br><div> case CmdShow of</div><div><b> SW_SHOWMINNOACTIVE: FMainForm.FWindowState := wsMinimized;</b></div><div> SW_SHOWMAXIMIZED: MainForm.WindowState := wsMaximized;</div><div> end;</div><div> if FShowMainForm then</div>
<div><b> if FMainForm.FWindowState = wsMinimized then</b></div><div><b> Minimize else</b></div><div> FMainForm.Visible := True;</div><div><br></div><div>The internal state is forced to <b>wsMinimize, </b>bypassing normal property setters, resulting in the "show" code simply calling the <b>Minimize</b> method on the main form, rather than making the form visible, which is why the FormShow even isn't fired. The form isn't shown! i.e. the <b>FormShow</b> event will eventually fire only when the user first activates the application and the window becomes shown. You could argue that this is desirable behaviour, but doesn't suit your purposes in this case.</div>
<div><br></div><div>This was changed in later versions of Delphi. The above code is from D7. The version below from XE4 (the only 2 versions I have available on this system):</div><div><br></div><div><div> case CmdShow of</div>
<div><b> SW_SHOWMINNOACTIVE:</b></div><div><b> begin</b></div><div><b> FInitialMainFormState := wsMinimized;</b></div><div><b> FMainForm.FWindowState := wsMinimized;</b></div><div><b> end;</b></div>
<div> SW_SHOWMAXIMIZED: MainForm.WindowState := wsMaximized;</div><div> end;</div><div> if FShowMainForm then</div><div><b> if (FMainForm.FWindowState = wsMinimized) or (FInitialMainFormState = wsMinimized) then</b></div>
<div><b> begin</b></div><div><b> Minimize;</b></div><div><b> if (FInitialMainFormState = wsMinimized) then</b></div><div><b> FMainForm.Show;</b></div><div> end else</div><div> FMainForm.Visible := True;</div>
</div><div><br></div><div>Now it appears that the <b>Show</b> method of your main form should be called, though I haven't tested to see whether this is actually the case. But in theory, <b>SW_SHOWMINNOACTIVE</b> should work for you if you upgrade the target EXE to a more current version of Delphi.</div>
<div><br></div><div>Alternatively, you could move the initialisation code in that EXE, currently triggered by the FormShow event, to a more appropriate initialisation event. After all, this is initialisation that needs to be performed regardless of whether the form is <b>Show'</b>n or not. ;)</div>
<div><br></div><div>It's possible that some of that code cannot be performed in <b>FormCreate</b>, which is a quite common reason to use <b>FormShow</b> instead. If that's the case, then one possible solution is to <b>post</b> a custom message to yourself in <b>FormCreate</b>, to fabricate the create-deferred event you need, without relying on the form being shown to generate the <b>FormShow</b> event:<br>
<br><br>const</div><div> MM_INITIALISE = WM_USER + 1;</div><div><br></div><div><br></div><div>TMyForm = class(TForm)</div><div> ...</div><div> procedure MMInitialise(var aMessage: TMessage); message MM_INITIALISE;</div>
<div>end;</div><div><br></div><div><br></div><div>TMyForm.FormOnCreate...<br></div><div>begin</div><div> PostMessage(Handle, MM_INITIALISE, 0, 0);<br> ...</div><div>end;</div><div><br></div><div><br></div><div><div>procedure TMyForm.MMInitialise(var aMessage: TMessage); </div>
</div><div>begin</div><div> // Do initialisation here...</div><div>end;</div><div><br></div><div><br></div><div><br></div><div>Good luck</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 25 July 2014 00:22, John Bird <span dir="ltr"><<a href="mailto:johnkbird@paradise.net.nz" target="_blank">johnkbird@paradise.net.nz</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div style="FONT-SIZE:12pt;FONT-FAMILY:'Calibri';COLOR:#000000">
<div>Hey that should have been perfect, as I already was doing SW_SHOWMINIMIZED
which works fine, and so does SW_SHOWNOACTIVE which also does what it
should – start the other window but not change focus.</div>
<div> </div>
<div>However SW_SHOWMINNOACTIVE doesn’t work. Now the other program
is a Delphi program of mine that does some initialisation in the Formshow event
(turning on timers etc) and I am wondering if somehow the event doesn’t
fire. The process starts, but nothing runs, looks asleep in Task Manager.
Not worth messing around with, as its a minor issue.</div>
<div><font face="Calibri"></font> </div>
<div>I toyed with using SW_SHOWINACTIVE and getting the program (Program B) to
minimise itself on start, but that is just damned complicated and
fiddly/fragile. It also seems prone to ending up with 2 icons on the task
bar, as though multiple copies have started even if only one is running – (maybe
due to the large amount of work it does on startup – it is unresponsive for a
good while) .</div>
<div> </div>
<div><font face="Calibri">I also tried Russells suggestion about
setting the foreground window and it don’t work for me (Windows
8.1)</font></div>
<div> </div>
<div>What I did in the end was go back to the SW_SHOWMINIMIZED and then after
the ShellExecute (in Program A) I put a ShowMessage saying I had started the
other program. Because this gives a modal clue that they have to
click on to continue it will do the job of setting the focus back. And its
a bit useful for them to be informed it has been started.</div>
<div style="FONT-SIZE:small;TEXT-DECORATION:none;FONT-FAMILY:"Calibri";FONT-WEIGHT:normal;COLOR:#000000;FONT-STYLE:normal;DISPLAY:inline">
<div style="FONT:10pt tahoma">
<div><font size="3" face="Calibri"></font> </div>
<div><font size="3" face="Calibri"></font> </div>
<div style="BACKGROUND:#f5f5f5">
<div><b>From:</b> <a title="jsmith@deltics.co.nz" href="mailto:jsmith@deltics.co.nz" target="_blank">Jolyon Smith</a> </div>
<div><b>Sent:</b> Thursday, July 24, 2014 8:21 PM</div>
<div><b>To:</b> <a title="russell@belding.co.nz" href="mailto:russell@belding.co.nz" target="_blank">Russell Belding</a> ; <a title="delphi@listserver.123.net.nz" href="mailto:delphi@listserver.123.net.nz" target="_blank">NZ
Borland Developers Group - Delphi List</a> </div>
<div><b>Subject:</b> Re: [DUG] Shellexecute question</div></div></div>
<div> </div></div>
<div style="FONT-SIZE:small;TEXT-DECORATION:none;FONT-FAMILY:"Calibri";FONT-WEIGHT:normal;COLOR:#000000;FONT-STYLE:normal;DISPLAY:inline"><div><div class="h5">
<div dir="ltr">Have you tried passing <strong style="FONT-SIZE:13px;FONT-FAMILY:'Segoe UI','Lucida Grande',verdana,arial,helvetica,sans-serif;COLOR:rgb(42,42,42);LINE-HEIGHT:18px">SW_SHOWMINNOACTIVE
instead of SW_MINIMIZED ?</strong>
<div><span style="FONT-SIZE:13px;FONT-FAMILY:'Segoe UI','Lucida Grande',verdana,arial,helvetica,sans-serif;COLOR:rgb(42,42,42);LINE-HEIGHT:18px"><br></span></div>
<div><span style="FONT-SIZE:13px;FONT-FAMILY:'Segoe UI','Lucida Grande',verdana,arial,helvetica,sans-serif;COLOR:rgb(42,42,42);LINE-HEIGHT:18px">Caveat:
The show flag parameter is merely passed to the application being
executed. What it chooses to do with that flag is it's own affair, but if
you're lucky, it will respect your wishes. If not, then you will have to
engage in a focus window arms race/lotto as already suggested. But Route
#1 would be to try the officially mandated mechanisms.<br><br>Good luck.
:)</span></div></div>
<div class="gmail_extra"><br><br>
<div class="gmail_quote">On 24 July 2014 19:46, russell <span dir="ltr"><<a href="mailto:russell@belding.co.nz" target="_blank">russell@belding.co.nz</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT:1ex;MARGIN:0px 0px 0px 0.8ex;BORDER-LEFT:#ccc 1px solid">
<div lang="EN-NZ" bgcolor="white" vlink="purple" link="blue">
<div>
<p class="MsoNormal"><span style="FONT-SIZE:11pt;FONT-FAMILY:"Calibri","sans-serif";COLOR:#1f497d">Tyr
this after spawning the other program.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="FONT-SIZE:11pt;FONT-FAMILY:"Calibri","sans-serif";COLOR:#1f497d"><u></u><u></u></span> </p>
<p class="MsoNormal"><span style="FONT-SIZE:11pt;FONT-FAMILY:"Calibri","sans-serif";COLOR:#1f497d">SetForegroundWindow(forms.application.mainWindow.handle)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="FONT-SIZE:11pt;FONT-FAMILY:"Calibri","sans-serif";COLOR:#1f497d"><u></u><u></u></span> </p>
<p class="MsoNormal"><span style="FONT-SIZE:11pt;FONT-FAMILY:"Calibri","sans-serif";COLOR:#1f497d">To
give the main window of your program focus.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="FONT-SIZE:11pt;FONT-FAMILY:"Calibri","sans-serif";COLOR:#1f497d">Perhaps
modifications of this will take you to the window of the calling program where
you want the focus?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="FONT-SIZE:11pt;FONT-FAMILY:"Calibri","sans-serif";COLOR:#1f497d"><u></u><u></u></span> </p>
<p class="MsoNormal"><span style="FONT-SIZE:11pt;FONT-FAMILY:"Calibri","sans-serif";COLOR:#1f497d">Russell<u></u><u></u></span></p>
<p class="MsoNormal"><span style="FONT-SIZE:11pt;FONT-FAMILY:"Calibri","sans-serif";COLOR:#1f497d"><u></u><u></u></span> </p>
<div>
<div style="BORDER-TOP:#b5c4df 1pt solid;BORDER-RIGHT:medium none;BORDER-BOTTOM:medium none;PADDING-BOTTOM:0cm;PADDING-TOP:3pt;PADDING-LEFT:0cm;BORDER-LEFT:medium none;PADDING-RIGHT:0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="FONT-SIZE:10pt;FONT-FAMILY:"Tahoma","sans-serif";COLOR:windowtext">From:</span></b><span lang="EN-US" style="FONT-SIZE:10pt;FONT-FAMILY:"Tahoma","sans-serif";COLOR:windowtext">
<a href="mailto:delphi-bounces@listserver.123.net.nz" target="_blank">delphi-bounces@listserver.123.net.nz</a> [mailto:<a href="mailto:delphi-bounces@listserver.123.net.nz" target="_blank">delphi-bounces@listserver.123.net.nz</a>] <b>On Behalf Of
</b>John Bird<br><b>Sent:</b> Thursday, 24 July 2014 4:43 p.m.<br><b>To:</b>
NZ Borland Developers Group - Delphi List<br><b>Subject:</b> [DUG]
Shellexecute question<u></u><u></u></span></p></div></div>
<div>
<div>
<p class="MsoNormal"><u></u><u></u> </p>
<div>
<div>
<div>
<p class="MsoNormal"><span style="FONT-SIZE:10pt;FONT-FAMILY:"Tahoma","sans-serif"">I have a program
(Program A) that fires up another (program B) via ShellExecute, if its
not already running. However even though Program B is started minimised,
focus shifts away from Program A, which is a minor nuisance.</span><span style="FONT-FAMILY:"Calibri","sans-serif""><u></u><u></u></span></p></div>
<div>
<p class="MsoNormal"><span style="FONT-FAMILY:"Calibri","sans-serif""><u></u><u></u></span> </p></div>
<div>
<p class="MsoNormal"><span style="FONT-SIZE:10pt;FONT-FAMILY:"Tahoma","sans-serif"">Is there any way
to stop this within Delphi? Or will I have to do something like delve
into the Windows API?</span><span style="FONT-FAMILY:"Calibri","sans-serif""><u></u><u></u></span></p></div>
<div>
<p class="MsoNormal"><span style="FONT-FAMILY:"Calibri","sans-serif""><u></u><u></u></span> </p></div>
<div>
<p class="MsoNormal"><span style="FONT-FAMILY:"Calibri","sans-serif"">if
ShellExecute(Application.Mainform.Handle, 'open', Pchar(aProgName),
PChar(aparaml), PChar(aDir), SW_SHOWMINIMIZED) <= 32
then<u></u><u></u></span></p></div>
<div>
<p class="MsoNormal"><span style="FONT-FAMILY:"Calibri","sans-serif"">
ShowMessage('Start Minimised error:')<u></u><u></u></span></p></div>
<div>
<p class="MsoNormal"><span style="FONT-FAMILY:"Calibri","sans-serif""><u></u><u></u></span> </p></div></div></div></div></div></div></div><br>_______________________________________________<br>NZ
Borland Developers Group - Delphi mailing list<br>Post: <a href="mailto:delphi@listserver.123.net.nz" target="_blank">delphi@listserver.123.net.nz</a><br>Admin:
<a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>Unsubscribe:
send an email to <a href="mailto:delphi-request@listserver.123.net.nz" target="_blank">delphi-request@listserver.123.net.nz</a>
with Subject: unsubscribe<br></blockquote></div>
<div> </div></div>
</div></div><p>
</p><hr><div class="">
_______________________________________________<br>NZ Borland Developers Group -
Delphi mailing list<br>Post: <a href="mailto:delphi@listserver.123.net.nz" target="_blank">delphi@listserver.123.net.nz</a><br>Admin:
<a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>Unsubscribe: send an email to
<a href="mailto:delphi-request@listserver.123.net.nz" target="_blank">delphi-request@listserver.123.net.nz</a> with Subject:
unsubscribe</div><p></p></div></div></div></div>
<br>_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe<br></blockquote></div><br></div>