简体   繁体   English

浏览器中的ShellExecute URL并不总是将焦点放在浏览器上

[英]ShellExecute url in browser does not always set focus on browser

I use ShellExecute in a GUI Aplication (created with Win API) to open a given hyperlink in the default browser of the user like: 我在GUI Aplication(使用Win API创建)中使用ShellExecute在用户的默认浏览器中打开给定的超链接,例如:

ShellExecute(0, 0, "www.stackoverflow.com", 0, 0, SW_SHOWMAXIMIZED); // Just an example

This works and the site is correctly openend in the default browser. 这可以正常工作,并且该站点在默认浏览器中已正确打开。

However, I want the browser to take focus once it is started. 但是,我希望浏览器在启动后能够集中精力。 At the moment this works only sometimes: say I execute the function like shown above in a button-click callback. 目前,这仅在某些情况下有效:说我在按钮单击回调中执行如上所示的功能。 Then it works as expected and the browser takes focus. 然后,它会按预期工作,浏览器将获得焦点。

However, it takes some time after the button click until the browser is opened. 但是,单击按钮后需要一段时间才能打开浏览器。 If I set the focus in the meantime to, say an edit control, the edit control (and with it the whole GUI) keeps the focus with the browser being opened in the background. 如果同时将焦点设置为某个编辑控件,则该编辑控件(以及整个GUI)将焦点保持在后台打开浏览器的状态。 But I want the behavior to be consistent such that the browser always takes the focus, regardless of the user interaction in the small time period after clicking on the button. 但是我希望行为保持一致,以使浏览器始终保持焦点,而不管用户在单击按钮后的一小段时间内是否进行交互。

How can this be achieved? 如何做到这一点?

I already tried ShellExecuteEx and WaitForInputIdle , then retrieving the main window handle from the process ID. 我已经尝试过ShellExecuteExWaitForInputIdle ,然后从进程ID检索主窗口句柄。 This however doesn't work unfortunatly, because ShellExecuteEx doesn't always return a process ID (even if SEE_MASK_NOCLOSEPROCESS is set)... 但是,这并不奏效,因为ShellExecuteEx并不总是返回进程ID(即使设置了SEE_MASK_NOCLOSEPROCESS )...

将“ open”指定为第二个参数(操作),而不是0 / NULL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM