<HTML><HEAD></HEAD>
<BODY 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&nbsp; which also does what it 
should – start the other window but not change focus.</DIV>
<DIV>&nbsp;</DIV>
<DIV>However SW_SHOWMINNOACTIVE doesn’t work.&nbsp;&nbsp; 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.&nbsp; The process starts, but nothing runs, looks asleep in Task Manager. 
Not worth messing around with, as its a minor issue.</DIV>
<DIV><FONT style="size: 3" face=Calibri></FONT>&nbsp;</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.&nbsp; 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>&nbsp;</DIV>
<DIV><FONT style="size: 3" 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>&nbsp;</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.&nbsp;&nbsp; Because this gives a modal clue that they have to 
click on to continue it will do the job of setting the focus back.&nbsp; 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>&nbsp;</DIV>
<DIV><FONT size=3 face=Calibri></FONT>&nbsp;</DIV>
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><B>From:</B> <A title=jsmith@deltics.co.nz 
href="mailto:jsmith@deltics.co.nz">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">Russell Belding</A> ; <A 
title=delphi@listserver.123.net.nz href="mailto:delphi@listserver.123.net.nz">NZ 
Borland Developers Group - Delphi List</A> </DIV>
<DIV><B>Subject:</B> Re: [DUG] Shellexecute question</DIV></DIV></DIV>
<DIV>&nbsp;</DIV></DIV>
<DIV 
style='FONT-SIZE: small; TEXT-DECORATION: none; FONT-FAMILY: "Calibri"; FONT-WEIGHT: normal; COLOR: #000000; FONT-STYLE: normal; DISPLAY: inline'>
<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:&nbsp; 
The show flag parameter is merely passed to the application being 
executed.&nbsp; What it chooses to do with that flag is it's own affair, but if 
you're lucky, it will respect your wishes.&nbsp; If not, then you will have to 
engage in a focus window arms race/lotto as already suggested.&nbsp; But Route 
#1 would be to try the officially mandated mechanisms.<BR><BR>Good luck.&nbsp; 
:)</SPAN></DIV></DIV>
<DIV class=gmail_extra><BR><BR>
<DIV class=gmail_quote>On 24 July 2014 19:46, russell <SPAN dir=ltr>&lt;<A 
href="mailto:russell@belding.co.nz" 
target=_blank>russell@belding.co.nz</A>&gt;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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 class=h5>
  <P class=MsoNormal><U></U><U></U>&nbsp;</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)&nbsp; via ShellExecute, if its 
  not already running.&nbsp; 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>&nbsp;</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?&nbsp; 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>&nbsp;</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) &lt;= 32 
  then<U></U><U></U></SPAN></P></DIV>
  <DIV>
  <P class=MsoNormal><SPAN style='FONT-FAMILY: "Calibri","sans-serif"'>&nbsp; 
  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>&nbsp;</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">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>
<DIV>&nbsp;</DIV></DIV>
<P>
<HR>
_______________________________________________<BR>NZ Borland Developers Group - 
Delphi mailing list<BR>Post: delphi@listserver.123.net.nz<BR>Admin: 
http://delphi.org.nz/mailman/listinfo/delphi<BR>Unsubscribe: send an email to 
delphi-request@listserver.123.net.nz with Subject: 
unsubscribe</DIV></DIV></DIV></BODY></HTML>