I have a full-screen Form maximized and always-on-top. Behind this Form, I have another window, which can be a browser, for example. In this case, visibly the browser window is the first big window behind my Form. How can I capture the handle only of this window behind my Form? I suspect that some change in this algorithm (that uses an EnumWindowsProc
callback) can be made to achieve this goal, but how?
Asked
Active
Viewed 128 times
0

Remy Lebeau
- 555,201
- 31
- 458
- 770
-
4Looks like you're looking for the next window in Z order. GetWindow might be all you need. E.g. `Wnd := Handle; repeat Wnd := GetWindow(Wnd, GW_HWNDNEXT); until IsWindowVisible(Wnd);` – Sertac Akyuz May 02 '21 at 23:34
-
Better check the result though, insert in the loop `if Wnd = 0 then Break;`. – Sertac Akyuz May 02 '21 at 23:45
-
The answers to this question https://stackoverflow.com/questions/825595/how-to-get-the-z-order-in-windows is probably what you are really looking for. – fpiette May 03 '21 at 05:36
-
@SertacAkyuz `Enum(Child)Windows()` is usually preferred instead of a `GetWindow()` loop. The main reason being the window list does not change during an `Enum...()` loop but it can during a `Get...()` loop. You can have an `Enum...` callback break the loop if a given condition is detected, in your example `IsWindowVisible()` – Remy Lebeau May 03 '21 at 16:09