问题描述
我想自动检测活动窗口无效的WPF应用程序的状态.
我使用了以下代码,但返回null
Application.Current.Windows.OfType<Window>().SingleOrDefault(w => w.IsActive);
Application.Current.Windows返回所有打开的窗口,但IsActive所有窗口的属性均为false.
如何解决此问题?
推荐答案
>>我使用了以下代码,但返回null
据我所知,窗口应用程序始终仅将一个窗口保留为活动窗口,该窗口是用户当前的前景窗口并具有焦点.在不活动的WPF应用程序中,没有窗口处于活动状态,没有焦点.所以我认为您的代码返回null窗口对象 我认为很好.
As far as I know, window application always only keep one windows as active window which is the user's current foreground window and has the focus. In the inactive WPF application, no window is active, no focus . So I think your code return null window object I think is fine.
>>如何解决此问题?
据我所知,您找不到无效WPF应用程序的活动"窗口.
As far as I know, you can not find Active window of an inactive WPF application.
也许您可以使用GetForegroundWindow来检索已聚焦窗口的句柄并获取窗口标题.
May be you can use GetForegroundWindow to retrieve the handle of the focused window and get the window title.
以下链接供您参考.
如何获取不属于我的应用程序的活动窗口:
http://stackoverflow.com/问题/32965310/如何获得不是我的应用程序一部分的活动窗口
How to get active window that is not part of my application:
http://stackoverflow.com/questions/32965310/how-to-get-active-window-that-is-not-part-of-my-application
如果我有任何误解,您可以提供所有其他必要的代码段,以便其他人可以从头开始重现您的问题以及有关结果的详细说明,包括任何异常消息.
If I have any misunderstanding, you can include all necessary code snippets for anyone else to be able to reproduce your issue from scratch along with a detailed description about the results including any exception messages.
最好的问候,
Best Regards,
Yohann Lu
Yohann Lu
这篇关于查找非活动WPF应用程序的“活动"窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!