如何确定当前窗口是否是活动窗口? [英] How to determine if the current window is the active window?

查看:861
本文介绍了如何确定当前窗口是否是活动窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何判断我的视窗是否为目前的活动视窗?
我当前的猜测是做GetForegroundWindow并将HWND与我的窗口的HWND进行比较。
有比这更好的方法吗?



我使用Win32 API / MFC。

解决方案

是的,这是我知道的唯一方法。



但是你必须处理GFW可以返回NULL的事实。通常,当其他桌面(例如屏幕保护程序桌面)处于活动状态时,会发生这种情况。请注意,使用保护程序密码可能会影响是否使用其他桌面(这是Windows版本相关的,我不记得不同版本工作原理的详细信息)。



另外这个代码在Visual Studio下的调试模式下不能正常工作,因为你将得到VS的窗口句柄。



除了一切都是peachy: p>

How can I tell if my window is the current active window? My current guess is to do GetForegroundWindow and compare the HWND with that of my window. Is there a better method than that?

I'm using Win32 API / MFC.

解决方案

Yes, that's the only way that I'm aware of.

But you have to handle the fact that GFW can return NULL. Typically, this happens when another desktop (e.g. the screen saver desktop) is active. Note that use of a saver password can affect whether a different desktop is used (this is windows version-dependent and I can't remember the details of how different versions work).

Also this code won't work properly in debug mode under Visual Studio, because you will get VS's window handle.

Other than that everything's peachy :-)

这篇关于如何确定当前窗口是否是活动窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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