- NSIS Discussion
- How to bring the App window to the front
Archive: How to bring the App window to the front
JamesKiller
26th March 2007 17:21 UTC
How to bring the App window to the front
When the installation comes to Finish page, I have a check box to Run our App.
The checkbox was checked, then i click on finish button. It dose get App running, but somehow,the window of our App sits behind the other windows.
How can I get our app's window to up front?
James
dienjd
26th March 2007 19:22 UTC
You can use FindWindow to get your app's HWND and then use an API, such as SetWindowPos to try to bring your app to the front. Note that Windows is restrictive about this at times. You can search the forums for that API to find specific examples with code.
Also, if your installer is one of the windows blocking your app, you can use HideWindow just before you launch it.
JamesKiller
26th March 2007 19:33 UTC
can you give me sample code..
Thank you..
dienjd
26th March 2007 19:43 UTC
Here's an example using SetForegroundWindow, which is probably the better call to use. If you didn't write your app, you can ask the developer or run Spy++ to get the app's window class.
FindWindow $0 "my app's window class" ""
IsWindow $0 0 +2
System::Call 'user32::SetForegroundWindow(i r0)'
JamesKiller
26th March 2007 21:03 UTC
where should I put those code? I can get the class name from spy++.
tried to put them into installer, seems to not work...
??
JamesKiller
26th March 2007 21:23 UTC
I think those code should be run after I click the finish button, the start our applicaiton, then bring it to up front. Otherwise,it can't find the window since app is not running yet.
???????
dienjd
26th March 2007 21:26 UTC
Yes, it has to be after your app runs but of course before your installer exits.
JamesKiller
26th March 2007 21:28 UTC
so where should I put those code? there is an Event like AfterClickFinishButton?
Thank you for your help.
dienjd
26th March 2007 21:30 UTC
If you are using MUI, see the MUI documentation for MUI_PAGE_CUSTOMFUNCTION_LEAVE
If not, see the docs for the Page instruction.
JamesKiller
26th March 2007 21:31 UTC
Yes, I am using MUI, thanks for your quick reply
JamesKiller
26th March 2007 21:53 UTC
But this button is on Finish Page, then run our application .exe file???
still not working
JamesKiller
26th March 2007 21:55 UTC
it is not a custom page.
dienjd
26th March 2007 22:26 UTC
Can you attach your script? It would make it a lot easier to help.
JamesKiller
26th March 2007 22:33 UTC
The installer's last page Finish Page.
!define MUI_FINISHPAGE_RUN_TEXT "' Start ${PRODUCT_NAME}'"
!insertmacro MUI_PAGE_FINISH
when installing the installer, after copying files, the comes to last page Finish window. If i click on Finish button on this window, then will run ${PRODUCT_NAME}.exe file. The problem is that ${PRODUCT_NAME}.exe window behind some windows, how can I get it to up front (topmost).
Any thoughts
Red Wine
26th March 2007 23:11 UTC
Try to add the provided by dienjd above code in function .onInstSuccess in loop to see if it makes the trick, e.g.
loop:
FindWindow $0 "my app's window class" ""
IsWindow $0 0 loop
System::Call 'user32::SetForegroundWindow(i r0)'
JamesKiller
27th March 2007 00:40 UTC
It does work for me!
Thank you very much, Red Wine.
I always can get answers from you. You are my saver!
Every time when I post my question here, always look forward to hearing from you.
Red Wine
27th March 2007 00:43 UTC
You're welcome :)
Thanks goes to dienjd for the provided solution ;)
JamesKiller
27th March 2007 00:44 UTC
Yes. Thanks Dienjd as well.
You guys save me one day work.