<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-NZ link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'>I use D7 and because my app can start minimized to the system tray/notification area with no OnFormShow firing, I got around the issue by changing the project file ...<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'>Application.CreateForm(...<o:p></o:p></span></p><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:#1F497D'>if StudioForm.Initialise then << added<o:p></o:p></span></b></p><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'>Application.Run<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'>My Initialise procedure has everything I need for initialising components and checking licence validation. If anything fails then it returns False and Application.Run is not executed. It works perfectly for me.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> delphi-bounces@listserver.123.net.nz [mailto:delphi-bounces@listserver.123.net.nz] <b>On Behalf Of </b>John Bird<br><b>Sent:</b> Friday, 25 July 2014 12:44 p.m.<br><b>To:</b> NZ Borland Developers Group - Delphi List<br><b>Subject:</b> Re: [DUG] Shellexecute question<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>It looks like the code in D2007 Application.Run is the later one. I would like to solve this at some stage out of curiosity so will return. The SW_SHOWMINIMIZED works as expected which is a puzzle. Usual story however, this is not on the list of urgent things to get working so it has to be put aside for now. <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>Its a good point you make about where to put startup code – my rule of thumb has generally been initialising non component stuff can be done in the form create, but I tend to put anything initialising component stuff on the form show event, and this is where much of it is – there is a bit of setting things visible or not depending on what properties are set and I don’t think this can generally be done before the Show event. This Program B does this general initialisation and then starts a timer which then fires of the rest of the startup code which is long running. Some of the long running code takes 20-40 seconds to run (calculations) and it doesn’t respond to minimising/maximising while that is happening which is another minor issue – I may need to put some extra processmessages calls in there eventually.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>This relates to a previous question – the long running calculation sets up some quite large arrays and I tried saving/reading them in from disk to bypass the calculations but it produced a stack overflow. I am presuming that this is not from the code, as Russell’s code to save and load arrays to disk ran standalone, but due to the program using a larger amount of memory. Another investigation for later on the list of priorities!<o:p></o:p></span></p></div><div><div><div><div><p class=MsoNormal style='background:whitesmoke'><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'> <a href="mailto:jsmith@deltics.co.nz" title="jsmith@deltics.co.nz">Jolyon Smith</a> <o:p></o:p></span></p></div><div><p class=MsoNormal style='background:whitesmoke'><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>Sent:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'> Friday, July 25, 2014 7:49 AM<o:p></o:p></span></p></div><div><p class=MsoNormal style='background:whitesmoke'><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>To:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'> <a href="mailto:delphi@listserver.123.net.nz" title="delphi@listserver.123.net.nz">NZ Borland Developers Group - Delphi List</a> <o:p></o:p></span></p></div><div><p class=MsoNormal style='background:whitesmoke'><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>Subject:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'> Re: [DUG] Shellexecute question<o:p></o:p></span></p></div></div></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div></div><div><div><p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-family:"Calibri","sans-serif";color:black'>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.... <o:p></o:p></span></p><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> case CmdShow of<o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> SW_SHOWMINNOACTIVE: FMainForm.FWindowState := wsMinimized;</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> SW_SHOWMAXIMIZED: MainForm.WindowState := wsMaximized;<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> end;<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> if FShowMainForm then<o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> if FMainForm.FWindowState = wsMinimized then</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> Minimize else</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> FMainForm.Visible := True;<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>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.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>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):<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> case CmdShow of<o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> SW_SHOWMINNOACTIVE:</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> begin</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> FInitialMainFormState := wsMinimized;</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> FMainForm.FWindowState := wsMinimized;</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> end;</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> SW_SHOWMAXIMIZED: MainForm.WindowState := wsMaximized;<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> end;<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> if FShowMainForm then<o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> if (FMainForm.FWindowState = wsMinimized) or (FInitialMainFormState = wsMinimized) then</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> begin</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> Minimize;</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> if (FInitialMainFormState = wsMinimized) then</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><b><span style='font-family:"Calibri","sans-serif";color:black'> FMainForm.Show;</span></b><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> end else<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> FMainForm.Visible := True;<o:p></o:p></span></p></div></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>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.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>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. ;)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>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<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> MM_INITIALISE = WM_USER + 1;<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>TMyForm = class(TForm)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> ...<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> procedure MMInitialise(var aMessage: TMessage); message MM_INITIALISE;<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>end;<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>TMyForm.FormOnCreate...<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>begin<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> PostMessage(Handle, MM_INITIALISE, 0, 0);<br> ....<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>end;<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>procedure TMyForm.MMInitialise(var aMessage: TMessage); <o:p></o:p></span></p></div></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>begin<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> // Do initialisation here...<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>end;<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>Good luck<o:p></o:p></span></p></div></div><div><p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-family:"Calibri","sans-serif";color:black'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>On 25 July 2014 00:22, John Bird <<a href="mailto:johnkbird@paradise.net.nz" target="_blank">johnkbird@paradise.net.nz</a>> wrote:<o:p></o:p></span></p><div><div><div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>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.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>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.<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>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) .<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>I also tried Russells suggestion about setting the foreground window and it don’t work for me (Windows 8.1)<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>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.<o:p></o:p></span></p></div><div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'> <o:p></o:p></span></p></div><div><div><p class=MsoNormal style='background:whitesmoke'><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'> <a href="mailto:jsmith@deltics.co.nz" target="_blank" title="jsmith@deltics.co.nz">Jolyon Smith</a> <o:p></o:p></span></p></div><div><p class=MsoNormal style='background:whitesmoke'><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>Sent:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'> Thursday, July 24, 2014 8:21 PM<o:p></o:p></span></p></div><div><p class=MsoNormal style='background:whitesmoke'><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>To:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'> <a href="mailto:russell@belding.co.nz" target="_blank" title="russell@belding.co.nz">Russell Belding</a> ; <a href="mailto:delphi@listserver.123.net.nz" target="_blank" title="delphi@listserver.123.net.nz">NZ Borland Developers Group - Delphi List</a> <o:p></o:p></span></p></div><div><p class=MsoNormal style='background:whitesmoke'><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>Subject:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'> Re: [DUG] Shellexecute question<o:p></o:p></span></p></div></div></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div></div><div><div><div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>Have you tried passing </span><strong><span style='font-size:8.0pt;font-family:"Segoe UI","sans-serif";color:#2A2A2A'>SW_SHOWMINNOACTIVE instead of SW_MINIMIZED ?</span></strong><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.0pt;font-family:"Segoe UI","sans-serif";color:#2A2A2A'>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><span style='font-family:"Calibri","sans-serif";color:black'><o:p></o:p></span></p></div></div><div><p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-family:"Calibri","sans-serif";color:black'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>On 24 July 2014 19:46, russell <<a href="mailto:russell@belding.co.nz" target="_blank">russell@belding.co.nz</a>> wrote:<o:p></o:p></span></p><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Tyr this after spawning the other program.</span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>SetForegroundWindow(forms.application.mainWindow.handle)</span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>To give the main window of your program focus.</span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;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?</span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Russell</span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:black'> <o:p></o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> <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</span><span style='color:black'><o:p></o:p></span></p></div></div><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:black'> <o:p></o:p></span></p><div><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>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='color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black'>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='color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-family:"Calibri","sans-serif";color:black'>if ShellExecute(Application.Mainform.Handle, 'open', Pchar(aProgName), PChar(aparaml), PChar(aDir), SW_SHOWMINIMIZED) <= 32 then</span><span style='color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-family:"Calibri","sans-serif";color:black'> ShowMessage('Start Minimised error:')</span><span style='color:black'><o:p></o:p></span></p></div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:black'> <o:p></o:p></span></p></div></div></div></div></div></div></div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'><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<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div></div></div></div><div class=MsoNormal align=center style='text-align:center'><span style='font-family:"Calibri","sans-serif";color:black'><hr size=3 width="100%" align=center></span></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>_______________________________________________<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<o:p></o:p></span></p></div></div></div></div></div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'><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<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'> <o:p></o:p></span></p></div></div><div class=MsoNormal align=center style='text-align:center'><span style='font-family:"Calibri","sans-serif";color:black'><hr size=3 width="100%" align=center></span></div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:black'>_______________________________________________<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">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<o:p></o:p></span></p></div></div></div></div></body></html>