Archive: focus issue of application after installation


focus issue of application after installation
  the issue is that when the user selects to run the application when the installation is complete, the application runs but the focus does not remain on the application.

can anybody please tell that is this NSIS issue or its my application issue.


*push*

I have the same question.
I am using the Modern UI and on the finish page MUI_FINISHPAGE_RUN to run my installed application.

This works so far without any problems but as shahil already wrote, the focus is not set to the application window.

Is there anything to do to change this behaviour?

Thanks,
Gunther


You need to use FindWindow followed by user32::SetForegroundWindow. You need to set up a RUN function and use Exec in there.

Stu


I sounds to me like the issue could be that whatever you are starting up is slow to create its window and the installer window closes fast, in that case, the app would lose the "right" to be foreground.

Just using a RUN function and a 2 second sleep after the exec might fix it


Stu,

thanks for your reply. I forgot to mention that I am already using a RUN function as I am using the UAC plugin and therefor the application should be started by the user who originated the setup.

Currently my function looks as follows:


ExecAppFile    

!insertmacro UAC_AsUser_ExecShell 'open' '$INSTDIR\opencpn.exe' '' '$INSTDIR' ''
FindWindow $0 '#32770' '' 0
System
::Call "user32::SetForegroundWindow(i r0) i."
>FunctionEnd
>
So in "normal" cases you only need the UAC_AsUser_ExecShell macro and the application gets automatically the focus.

But in some cases my application starts with a message box before the application window exists. The window title is localized (by the application) so I don't know it. And as there is also no window parent I cannot use it, too.

The only thing I know for sure in this case is the name of the process.
Is there any way to bring the message box to the front?

Thanks,
Gunther

Try using just "Sleep 3000" no findwindow etc


Anders,

I could have come to this conclusion myself as actually adding a sleep command seems to be the "universal" solution for all my problems .... ;)

Originally posted by Anders
Try using just "Sleep 3000" no findwindow etc
I tried it with 2000 and it worked.

But all these ugly sleep commands are a bit unpleasent, especially as e.g. the time needed by the application to launch may differ from user/ system to user/ system.

Do you think that a loop checking for the process being started could be an alternative?

Thanks,
Gunther

I'd use a loop until IsWindow returns true and shorten the Sleep.

Stu


Stu,

my problem is how to get the handle of the message box?


Ugly hack:


Exec '"calc.exe"'

>loop:
System::Call user32::GetForegroundWindow()i.r0
Sleep 200
IntCmpU$0 $hwndparent loop
>

Ugly or not - better than just the sleep command in any case! ;)
Thanks Anders - works! :up:

Gunther