检查其他应用程序是否具有焦点. [英] Check if other app has focus .

查看:162
本文介绍了检查其他应用程序是否具有焦点.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SendKeys api将按键发送到其他一些应用程序.当应用失去焦点时,我想停止此操作.是否可以检查其他应用程序是否具有焦点,或者更好地使应用程序不能失去焦点?在此先谢谢您.

I use SendKeys api to send keystokes to some other app. I want to stop this when app loses focus . Is there posibility to check if other app has focus or even better to make app can''t lose focus ? Thanks in advance.

推荐答案

要使窗口焦点,请使用Windows api函数setForgroundWindow.

有关MSDN的相关信息,请点击此处.

http://msdn.microsoft.com/en-us/library/ms633539%28v = vs.85%29.aspx [ ^ ]
To make a window focus use the windows api function setForgroundWindow.

MSDN decumentation about it here.

http://msdn.microsoft.com/en-us/library/ms633539%28v=vs.85%29.aspx[^]


对于表单,Form''s焦点"实际上是它的激活;您可以使用Form.Activate.如果这是某些非形式的Windows,则可以使用Albin的答案.要知道窗口是否在前台,您应该使用Windows API GetForegroundWindow,该API返回HWND并与相关窗口的HWND进行比较.您需要同时使用P/Invoke和SetForegroundWindow.

这将无法解决您的问题.有关完整分辨率,请参见以下两个答案:

应用程序焦点的得失 [在BACKSPACE按钮上编程 [
For forms, a Form''s "focus" is actually it''s activation; you can use Form.Activate. If this is some Windows which is not a form, you can use the Answer by Albin. To know if a Window is in foreground you should use Windows API GetForegroundWindow which returns HWND and compare with HWND of the Window in question. You need to use P/Invoke as well as for SetForegroundWindow.

This along will not solve your problem. For full resolution, please see these two Answers:

Application focus getting and losing[^]
Programming on BACKSPACE button[^]

—SA


这篇关于检查其他应用程序是否具有焦点.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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