在NSIS中调用两个浏览器窗口时,如何确保最后一个获得焦点?

发布于 2024-11-07 16:50:08 字数 747 浏览 0 评论 0原文

我有这个 nsis 脚本,

……

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\Internet Explorer\iexplore.exe" "http://www.google.ca"' '' ''

exe_done:

问题是,随机地,我在前台获得 FIRST 窗口,在后面获得 SECOND 窗口 有时我会在第一窗口前面看到第二窗口。

我的猜测是,这是由于 FIRST 窗口需要随机时间打开并且 如果SECOND窗口在FIRST窗口之前完成打开,则FIRST窗口将获得焦点并位于顶部。

有谁有解决方案来确保SECOND窗口具有焦点?

谢谢你!

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\Internet 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋风の叶未落 2024-11-14 16:50:08

这不是一个简单的问题,因为打开网页是异步的:您不知道加载何时完成。一个优雅的解决方案是从浏览器获取第一页已加载的反馈,但这需要大量工作,因为您必须支持每个浏览器。顺便说一句,你强制使用 IE,这不是一个好主意,你应该使用用户的默认浏览器

也许一些 AutoIt< /a> 脚本可以监视并等待浏览器窗口/选项卡打开。

或者只需在两次通话之间等待几秒钟。

编辑

请参阅这篇文章 还有这个

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

·深蓝 2024-11-14 16:50:08

使用这个简单的循环将所需的窗口置于前面。 (我使用了 Exec,但与 UAC 和 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)"

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)"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文