Detect when window gets overlapped by another window from the same or different process

2k Views Asked by At

Background

We are running our application in XenDesktop mode and our window shows some real time information. But if some other application is also launched in that XenDekstop and that application is overlapping our window then we want to stop rendering. And once its moved out of our window then we want to start rendering again. Unfortunately, right now these kind of notifications are not supported by Citrix.

Question

How can we detect when a part or the whole of the application window has been overlapped by other windows, and also detect when that's no longer the case?

I found the WindowFromPoint family of functions when Googling, however, that is not practical for my purpose because I'd need to keep polling all co-ordinates that my window covers.

Bonus points: For a start, it's enough if I can just detect when such overlapping occurs. However, if I can detect exactly which area(s) of my window is/are covered that would be great.

3

There are 3 best solutions below

4
Medinoc On

I think you should be able to get this kind of information when processing the WM_PAINT message, since normally the clipping region would be set accordingly. Calls to the RectVisible() function should tell you, for any part of your window, whether it "should be painted" (and so, whether it was just uncovered).

1
xMRi On

There is no such API function. And usually the it isn't needed. WM_PAINT cares for itself.

If you get a WM_PAINT message you receive a region and a update rectangle of the area that needs a repaint. But it is a rectangle only, no complex region. Also there is a clipping region too.

But it should be possible to calculate the region by yourself. If we are talking about a top level window.

  • Create a rectangular region that is consists of your window rect
  • Walk all top level windows from back to front
  • Ignore all windows until you find your top level window
  • For each visible top level window create a rectangular region and XOR it with your current one.
  • Should be easy with GetWindow GW_HWNDNEXT

The resulting region is what you are searching for.

Again: There is no such function or message that determine, that is fired or can be executed to find such overlapping. There is no need for such an information. The system cares for itself with the appropriate WM_PAINT message. If an area is covered. There is no need for an action. If an area is uncovered WM_PAINT gets fired.

0
SZIEBERTH Ádám On

Despite this is not a solution to the OP's problem, I want to remark that once an overlapping window reveals part of your window (and also if you drag more area of your window back to screen), you will get a WM_ERASEBKGND message before the WM_PAINT.