如何强制我的应用程序来到前面,并采取焦点? [英] How do I force my app to come to the front and take focus?

查看:134
本文介绍了如何强制我的应用程序来到前面,并采取焦点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个应用程序,恰恰是我正在工作的安装程序的引导程序。该应用程序进行几个MSI调用,以获取我需要的信息,将我的应用程序的主窗口的向导,这将导致一个进度窗口打开时,信息被收集,然后消失一旦完成。然后设置并启动向导。我的问题是,向导(派生自CPropertySheet)不想来到前面,并成为活动应用程序,没有我添加一些调用这样做。

I'm working on an application that happens to be the bootstrap for an installer that I'm also working on. The application makes a few MSI calls to get information that I need for putting together the wizard that is my application's main window, which causes a progress window to open while the info is being gathered and then go away once that's done. Then the wizard is set up and launched. My problem is that the wizard (derived from CPropertySheet) does not want to come to the front and be the active application without me adding in some calls to do so.

我在我的OnInitDialog()方法中使用以下代码解决了将它带到前面的问题:

I've solved the problem of bringing it to the front with the following code in my OnInitDialog() method:

SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); // force window to top
SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); // lose the topmost status that the previous line gave us

我的问题是我还没有想出了如何使窗口自激活(即,使自己成为具有焦点的一个)。 SetFocus()在此上下文中不起作用。我需要的东西,将强制窗口的Z顺序的顶部,并激活它,最好在尽可能少的调用。

My problem is that I still haven't figured out how to make the window self-activate (i.e., make itself be the one that has the focus). SetFocus() won't work in this context. I need something that will force the window to the top of the Z-order and activate it, preferably in as few calls as possible.

我的猜测是进度窗口打开在开始的MSI调用是导致主窗口拧紧,但我没有办法防止该窗口出现。另外,隐藏它是没有意义的,因为它让用户知道在主窗口到达之前发生了什么。

My guess is that the progress window opened at the beginning by the MSI calls is causing the main window to screw up, but I have no way to prevent that window from appearing. Also, it wouldn't make sense to hide it, because it lets the user know what's going on before the main window arrives.

推荐答案

p>你不能偷焦。

请参阅此新旧文章:

https://blogs.msdn.microsoft.com/oldnewthing/20090220-00/?p=19083

这篇关于如何强制我的应用程序来到前面,并采取焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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