开发者

When calling two browser windows in NSIS, how to make sure the last one gets focus?

开发者 https://www.devze.com 2023-03-06 09:38 出处:网络
I have this nsis script, ... nsExec::Exec \"openFirstWindow.exe\";HERE This exe will open a FIRST WINDOW to whatever url

I have this nsis script,

...

nsExec::Exec "openFirstWindow.exe"  ;HERE This exe will open a FIRST WINDOW to whatever url

Pop $exe_return_code
StrCmp $exe_return_code "0" exe_success
Goto exe_done
exe_success:
    ;HERE is the call to the SECOND WINDOW
    UAC::Exec '' '"$PROGRAMFILES\I开发者_运维知识库nternet Explorer\iexplore.exe" "http://www.google.ca"' '' ''

exe_done:

...

The problem is that randomly, I get the FIRST window in foreground and the SECOND behind, and sometimes I get the SECOND window in front of the FIRST.

My guess is that it is due to the FIRST window taking random time to open and if the SECOND window finishes opening before the FIRST one, then the FIRST one will get the focus and be on top.

Does anyone have a solution to make sure that the SECOND window has focus ?

Thank you!


This is not a simple problem, because opening a web page is asynchronous: you don't know when the loading has finished. An elegant solution would be to have a feedback from the browser that the first page has loaded, but it's a lot of work since you'd have to support every browser. By the way you force the use of IE, it's not a good idea, you should use the user's default browser

Maybe some AutoIt script can watch and wait for the browser window/tab to open.

Or simply wait for a few seconds between both calls.

EDIT

See this post and this one too


Use this simple loop to bring required window in the front. (I used Exec, but works fine with UAC and nsExec)

; This Window is opened as first
Exec '"$PROGRAMFILES\Internet Explorer\iexplore.exe" "www.google.sk"' 
; This is opened later
Exec '"$PROGRAMFILES\Internet Explorer\iexplore.exe" "www.unsigned-softworks.sk/installer"'  

CheckWindow:
  Sleep 500 ; Wait some time (miliseconds)

  ; Find by Window class and by Window name 
  FindWindow $1 "IEFrame" "Google - Windows Internet Explorer" 

  ; If window is not found (not loaded!) search again 
  IntCmp $1 0 CheckWindow Continue Continue

Continue:
  # If found (opened & loaded), bring it to front
  System::Call "User32::SetForegroundWindow(i) b ($1)"
0

精彩评论

暂无评论...
验证码 换一张
取 消