我可以检测到窗口是否部分隐藏? [英] Can I detect if a window is partly hidden?

查看:433
本文介绍了我可以检测到窗口是否部分隐藏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检测到我的程序外的窗口是否1)完全可见,2)部分隐藏,或3)完全隐藏?如果窗口(基于检索的句柄)不可见,我想要能够告诉我的应用程序不做任何事情。我不在乎窗口是否有焦点,什么是z顺序,还是其他任何东西,我只是感兴趣的窗口显示多少。如果我需要别的东西来取得这个,我没事,可以吗?谢谢。

Is it possible to detect if a window for a program outside mine is 1) completely visible, 2) partly hidden, or 3) completely hidden? I want to be able to tell my application not to do anything if a window (based on a retrieved handle) isn't visible. I don't care if the window has focus or not,what the z order is, or anything else, I'm just interested in how much of the window shows. If I need something else to get this, I'm fine, but is it possible? Thanks.

推荐答案

Raymond Chen写了几篇关于这个的文章

Raymond Chen wrote an article about this a few years ago.

它的要点可以使用 GetClipBox 来告诉你窗口的设备上下文有什么样的裁剪区域。空区域意味着窗口完全模糊,复杂区域意味着窗口部分被遮挡。如果它是一个简单(矩形)区域,则可视性取决于可视矩形是否与窗口的边界重合。

The gist of it is that you can use GetClipBox to tell you what kind of clipping region a window's device context has. A null region means the window is totally obscured, and a complex region means it's partially obscured. If it's a simple (rectangular) region, then visibility depends on whether the visible rectangle coincides with the bounds of the window.

只能由一个线程使用DC一次因此,您不应该获取一个不是您的应用程序的窗口的DC。否则,您可能会遇到其他应用程序(不知道您在做什么)的情况,尝试在您仍然使用它来检查裁剪区域时使用其DC。尽管如此,使用它可以非常安全地判断您自己的窗口。

A DC can only be used by one thread at a time. Therefore, you should not acquire the DC of a window for an application that isn't yours. Otherwise, you may encounter a situation where the other application — unaware of what you're doing — attempts to use its DC while you're still using it to inspect the clipping region. It should be perfectly safe to use it to make judgments about your own windows, though.

这篇关于我可以检测到窗口是否部分隐藏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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