Click to See Complete Forum and Search --> : Are any windows overlapping my window?


rexx
July 28th, 2009, 11:20 AM
Say I have a handle to a window ("my" window). I would like to know if there are any other windows "on top" of it.

I think I can use EnumWindows and then GetWindowRect on each window and see if any overlap my window. If so, use WindowFromPoint to find out who is on top.

But this seems like a lot of work! Does anyone know an easier method?

Also, I think I remember seeing a Windows function to determine overlap (if any) of two windows, but I can't find it now. Is there such a function, or have I made that up? (I know I can do a mess of subtraction, but...)

JVene
July 28th, 2009, 01:07 PM
I should qualify before I go on that I don't consider myself an expert on Windows API, though I've used it for years and at one time was more familiar with it, but I've happily let that go in favor of frameworks like Qt.

That said, I don't believe there is a function which specifically tells you if two windows overlap - you may be thinking of MFC or other framework's ability to to compare the rectangles take from two windows which can.

The GetNextWindow API may be the most useful to you (or it's MFC counterpart). With that, you should be able to walk through those windows who's Z order is on top of yours. While these may not all be obscuring your window, they are the only one's that could, and that minimizes your search population.

After that, it is going to be a matter of comparing the overlap of the window's rectangular region, though some windows could conceivably be non-rectangular in form, and if so, a simplification that assumes a bounding rectangle may occasionally return false positives unless you researched the entire bounding region.

These tests are fairly quick, probably faster than asking the API for the candidate windows in the first place.

shalo
July 29th, 2009, 06:25 AM
i am new with APIs. so, i am not sure but may be you should check for GetRunningWindow () ... i hope it helps...

Arjay
July 29th, 2009, 03:02 PM
One thing that might help is to consider the z-order of the window. This will allow you to determine which windows are on top of your windows. That way you can ignore the ones below you.

Search google for "Window z-order enumwindows"

carl666
August 1st, 2009, 01:08 PM
Also, I think I remember seeing a Windows function to determine overlap (if any) of two windows

Yes, it's a classic one (see on google groups, Win32 overlapping, same one than on 16-bits)