确定矩形在窗口内是否可见
我想确定窗口内的矩形是否完全可见。
我找到了 RectVisible,但该函数确定矩形的任何部分是否可见,我想知道整个矩形是否可见。
有没有这方面的功能?
I would like to determine if a rect inside a window is completly visible.
I have found RectVisible, but that function determines if any part of the rect is visible, I want to know if the entire rect is visible.
Is there any function for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先使用
GetRandomRgn
。在此处了解有关“系统区域”的更多信息。然后,偏移该区域,因为它位于屏幕坐标中(我链接的文章有一个示例)。之后,使用从矩形创建一个区域CreateRectRgn
并将“矩形区域”的部分与不属于“系统区域”的部分组合起来:即调用CombineRgn
将矩形区域作为第一个区域,将系统区域作为第二个区域,RGN_DIFF
作为fnCombineMode
。如果结果是 NULLREGION ,那么您的矩形是完全可见的 - 它没有完全或部分被任何窗口(顶层或非顶层)覆盖,或者它没有完全或部分离开屏幕。总而言之,您很可能以错误的方式处理问题。如果您已经讲述了您一直在努力实现的目标,那么某人可能会建议一种更简单的方法。
First get the system clipping region (the visible region of a window) into a region by using
GetRandomRgn
. Read more about the 'system region' here. Then, offset that region since it is in screen coordinates (the article I linked has an example). After that, create a region from your rectangle withCreateRectRgn
and combine the parts of your 'rectangle region' with those that are not part of the 'system region': that is callingCombineRgn
passing the rectangle region as the first region, and the system region as the second region, andRGN_DIFF
as thefnCombineMode
. If the result isNULLREGION
then your rectangle is fully visible - it is not fully or partially covered by any window (top level or not), or it is not fully or partially off-screen.All in all, there's a probability that you're approaching your problem the wrong way around. If you've told what you've been trying to achieve someone could probably suggest a simpler approach.
在每个角落使用 PtVisible长方形。
Use PtVisible on each corner of the rectangle.
你能用窗口和矩形的坐标做一个简单的比较吗?
检查矩形的左纵坐标是否位于窗口左边框的右侧;右纵坐标位于窗口右边框的左侧;顶部和底部类似吗?
唯一的问题可能是如果您同时使用逻辑坐标和物理坐标,在这种情况下您将需要执行转换。
Can you do a simple comparison using the coordinates of the window and the rectangle.
Check the rectangle's left ordinate is to the right of the Window's left border; the right ordinate is to the left of the Window's right border; and similar for top and bottom?
The only wrinkle might be if you are using both logical and physical coordinates, in which case you will need to perform a transformation.
所有处理剪辑矩形和点可见性的功能都与 Windows Vista 的新桌面合成功能无关。这些函数在 Windows XP 及更早版本以及关闭 Aero/Desktop Composition 的 Windows 7 上可以正常工作,但除此之外,它们将始终声称整个窗口可见。
All the functions that dealt with clip rectangles and point visibility broke with Windows Vista's new desktop composition feature. The functions will work fine on Windows XP and earlier, and on Windows 7 with Aero/Desktop Composition turned off, but otherwise, they will always claim that the entire window is visible.