如何判断一个窗口是否有焦点?(Win32 API) [英] How can I tell if a window has focus? (Win32 API)

查看:37
本文介绍了如何判断一个窗口是否有焦点?(Win32 API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Win32 API(在 C 中,但这无关紧要),如何判断给定窗口(由 HWND 标识)是否具有焦点?

Using the Win32 API (in C, but that's inconsequential), how can I tell if a given window (identified by HWND) has focus?

我正在挂钩一个监视事件的应用程序,当该事件发生时,我想检查该应用程序是否已经获得焦点.如果没有,我想闪烁窗口,直到他们把焦点放在它上面.

I'm hooking an application watching for an event, and when that event occurs I want to check if the application already has focus. If it doesn't, I want to flash the window until they give focus to it.

或者,如果窗口已经有焦点,FlashWindowEx 结构标志 FLASHW_TIMERNOFG 是否会闪烁直到窗口获得焦点才不会闪烁?

Alternately, does the FlashWindowEx struct flag FLASHW_TIMERNOFG that flashes until the window has focus just not flash if the window already has focus?

我现在无法测试这个,因为我不在我的开发环境中,但我的印象是它无论如何都会闪烁,这是我试图避免的.

I cannot test this now since I am not in my development environment, but I was under the impression that it would flash anyways, which is what I'm trying to avoid.

此外,如果重要的话,应用程序在此窗口中使用 DirectX.

Also, if it matters, the application uses DirectX in this window.

推荐答案

GetActiveWindow 将返回与输入焦点相关联的顶级窗口.GetFocus 将返回具有输入焦点.

GetActiveWindow will return the top-level window that is associated with the input focus. GetFocus will return the handle of the window that has the input focus.

这篇文章可能会有所帮助:
http://www.microsoft.com/msj/0397/Win32/Win320397.aspx

This article might help:
http://www.microsoft.com/msj/0397/Win32/Win320397.aspx

这篇关于如何判断一个窗口是否有焦点?(Win32 API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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