Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I detect if a window is partly hidden?

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.

like image 812
Tom A Avatar asked Dec 23 '22 01:12

Tom A


1 Answers

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

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.

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.

like image 74
Rob Kennedy Avatar answered Jan 09 '23 10:01

Rob Kennedy