Determine if a rect is visible inside window

徘徊边缘 提交于 2019-12-07 20:06:48

问题


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?


回答1:


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 with CreateRectRgn and combine the parts of your 'rectangle region' with those that are not part of the 'system region': that is calling CombineRgn passing the rectangle region as the first region, and the system region as the second region, and RGN_DIFF as the fnCombineMode. If the result is NULLREGION 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.




回答2:


Use PtVisible on each corner of the rectangle.

The PtVisible function determines whether the specified point is within the clipping region of a device context.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/4071810/determine-if-a-rect-is-visible-inside-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!