使用ShellExecute打开URL-C ++中的SW_SHOWMAXIMIZED不活动窗口 [英] Open URL with ShellExecute - SW_SHOWMAXIMIZED dont active window in C++

查看:126
本文介绍了使用ShellExecute打开URL-C ++中的SW_SHOWMAXIMIZED不活动窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此功能在Chrome中打开新标签页并将其激活:

I used this function to open new tab in Chrome and active it:

ShellExecuteA(0,0,"chrome.exe","http://google.com  --incognito",0,SW_SHOWMAXIMIZED);

但Chrome仅打开新标签页,但没有活动窗口.
(如果用户按下指定的键,则从没有用户界面的应用程序的全局键盘挂钩中调用此函数.)

but Chrome only open new tab but it doesnt active window.
(I call this function from global keyboard-hook of an application with no user interface, if user press specified key).

我该如何解决?

推荐答案

看起来像chrome.exe中的错误.如果常规(非隐身)chrome.exe会话正在运行,并且没有隐身会话在运行,我可以通过一个简单的控制台应用程序使用您的ShellExecute调用进行复制.换句话说,如果需要生成新的隐身Chrome会话,则常规会话似乎不会正确地将ShowWindow标志传播到生成的隐身进程.另一个因素是,激活失败还要求常规的Chrome会话在测试应用运行之前处于活动状态.如果其他任何应用程序处于活动状态(例如notepad.exe),则隐身会话的激活成功. ShellExecuteExCreateProcess也会发生相同的行为.在Process Explorer中(从sysinternals中观察),很明显chrome.exe会根据需要派生子进程,然后终止自身.这使得很难拦截hProcess或processId以便最终调用SetActiveWindow.

Looks like a bug in chrome.exe. I could repro with your ShellExecute call from a simple console app, if a regular (non-incognito) chrome.exe session was running and no incognito session was running. In other words, if a new incognito chrome session needed to be spawned, the regular session did not appear to correctly propagate the ShowWindow flags to the spawned incognito process. Another factor was that the activation failure also required the regular chrome session to be active before the test app ran. If any other app was active (say notepad.exe), then activation of the incognito session succeeded. The same behavior occurs with ShellExecuteEx and CreateProcess. Observing in Process Explorer (from sysinternals), it's clear that chrome.exe is forking the child process as necessary and then terminating itself. This makes it difficult to intercept an hProcess or processId in order to ultimately call SetActiveWindow.

这篇关于使用ShellExecute打开URL-C ++中的SW_SHOWMAXIMIZED不活动窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆