How to check if a window is fully behind others? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
KilliK
Posts: 224
Joined: 10 Mar 2016, 21:19

How to check if a window is fully behind others?

26 Mar 2019, 10:54

Hello.
Is there a reliable way to check whether a window is fully covered behind other windows?
I have a small window which is kept non-activated in the right side of the screen, next to another focused window. That small window sometimes gets hidden behind other windows, and I need to manually bring it in front, next to the main window. I want to automate this process with AHK, but I dont know how to trigger it only when that window gets hidden.

I have tried to put it in AlwaysOnTop, but that conflicts with the other windows, so I want to avoid this approach.
I cant use WinGet to check if it gets minimized, because it doesnt, it stays opened and only goes behind the other windows.
Checking for a specific color or pixel on the window is not reliable, and I want to avoid it.
I tried the suggestions from this topic, but none works:
https://autohotkey.com/board/topic/58933-how-to-check-if-a-window-is-hidden/

There is also this post discussing this, but again not much of a help:
https://www.autohotkey.com/boards/viewtopic.php?t=4045

Any other idea how I can do this?
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to check if a window is fully behind others?

02 Apr 2019, 21:49

You could use this:
check if rectangles (windows) overlap - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=30809

In the worst-case scenario, a window is *partially* overlapped by another window, and you then have multiple smaller rectangles (the non-overlapped parts), and you have to check if those are overlapped. And this process can repeat, with multiple small bits of window to check.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Kobaltauge
Posts: 225
Joined: 09 Mar 2019, 01:52
GitHub: MassimoCastell
Location: Germany
Contact:

Re: How to check if a window is fully behind others?

02 Apr 2019, 23:49

KilliK wrote:
02 Apr 2019, 21:42
anyone?
Normally a window comes on top when you put the focus on it. Wouldn't it work if you minimize and mazimize it before you do your action?
I know it's a sloppy way but a solution.
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to check if a window is fully behind others?

02 Apr 2019, 23:59

You could get the window position using WinGetPos, and then do MouseGetPos at various points (or DllCall with WindowFromPoint) to get the window under the cursor.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
iPhilip
Posts: 431
Joined: 02 Oct 2013, 12:21

Re: How to check if a window is fully behind others?  Topic is solved

03 Apr 2019, 03:08

Hi KilliK,

Would you let me know if the code below works for you?

Code: Select all

F3::  ; Set the window to keep active and start the timer
hwnd := WinExist("A")
SetTimer, Timer, 100
Return

Timer:
WinGet, ID, List, , , Program Manager
Loop, %ID% {
   if (ID%A_Index% = hwnd)
      Break
   if IsWinCover(ID%A_Index%, hwnd) {
      WinActivate, ahk_id %hwnd%
      Break
   }
}
Return

; Returns true if hwnd1 completely covers hwnd2

IsWinCover(hwnd1, hwnd2) {
   WinGetPos, X1, Y1, W1, H1, ahk_id %hwnd1%
   WinGetPos, X2, Y2, W2, H2, ahk_id %hwnd2%
   Return X1 <= X2 && Y1 <= Y2 && X1+W1 >= X2+W2 && Y1+H1 >= Y2+H2
}

Esc::ExitApp
Cheers!

- iPhilip
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
KilliK
Posts: 224
Joined: 10 Mar 2016, 21:19

Re: How to check if a window is fully behind others?

03 Apr 2019, 08:31

iPhilip, I checked your code and it works very well, it does exactly what I need. thank you very much.
iPhilip
Posts: 431
Joined: 02 Oct 2013, 12:21

Re: How to check if a window is fully behind others?

03 Apr 2019, 09:35

You are very welcome. :)
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)

Return to “Ask For Help”

Who is online

Users browsing this forum: asad41163, flyingDman, Gay Kiwi, Google [Bot], scriptor2016, Tom Harding, WAZAAAAA and 213 guests