Hi,
how do I implement this functionality "raise window if partially hidden beneath something, otherwise lower it" in ahk, ie is there a "IsWinPartiallyHidden" that I can use in:
#1::
MouseGetPos, , , id,
If IsWinPartiallyHidden(id) {
WinSet, Top, , ahk_id %id%
} else {
WinSet, Bottom, , ahk_id %id%
}
return
Thank you.
Does IsWinPartiallyHidden exists? Topic is solved
-
- Posts: 2
- Joined: 09 Dec 2018, 16:42
Re: Does IsWinPartiallyHidden exists?
Hallo,
try:But it only tests the 4 window corners!
try:
Code: Select all
#1::
CoordMode, Mouse, Screen
MouseGetPos, mx, my, ID
WinGetPos, x, y, w, h, ahk_id %id%
w--
h--
IF InWin(x,y,ID) And InWin(x+w,y,ID) And InWin(x+w,y+h,ID) And InWin(x,y+h,ID)
WinSet, Bottom, , ahk_id %id%
Else
WinSet, Top, , ahk_id %id%
MouseMove, mx, my, 0
Return
InWin(x,y,ID)
{
CoordMode, Mouse, Screen
MouseMove, x, y, 0
MouseGetPos,,, MID
Return, (MID = ID)
}
Re: Does IsWinPartiallyHidden exists?
A while ago I needed something similar. I couldn't find such a function. I thought about getting all windows z-order and checking whether the bounding coordinates encompassed the target window bounding coordinates or vice versa, but with transparancy and non-rectangular overlapping windows that wouldn't work. Instead I just checked a grid of points on the target window, whether the 'visible' point is the target. It won't work right if the target isn't rectangular and I doubt it will register click-through windows covering it, but it did the job.
Code: Select all
WinIsUnobscured(Wintitle, Margin:=-1, Grid:=25){
If !(hTarget:=WinExist(Wintitle))
Return 0
If (Margin<0){
WinGet,Style,Style,% WinTitle
If (Style & 0x40000) ;WS_SIZEBOX
SysGet,Margin,32
Else If (Style & 0x40000) ;
SysGet,Margin,5
Else Margin:=0
}
WinGetPos,x,y,w,h,% Wintitle
x1:=x+Margin, y1:=y+Margin, x2:=x+w-Margin, y2:=y+h-Margin
Loop {
xx:=(xx:=x1+(A_Index-1)*Grid) > x2 ? x2 : xx
Loop {
yy:=((yy:=y1+(A_Index-1)*Grid) > y2) ? y2 : yy
hWnd:=DllCall("WindowFromPoint", "int64", (yy << 32) | (xx & 0xFFFFFFFF))
hWnd:=DllCall("GetAncestor", "Uint", hWnd, "Uint", 2)
If (hWnd!=hTarget)
Return 0
}Until yy=y2
}Until xx=x2
Return 1
}
Re: Does IsWinPartiallyHidden exists? Topic is solved
What about this:
Code: Select all
F1:: SetTop_Toggle_WinUnderMouse()
SetTop_Toggle_WinUnderMouse(){
MouseGetPos,,, WinUnderMouse
WinGet, ID_WuM, ID, ahk_id %WinUnderMouse%
If NOT IsWindow(WinExist("ahk_id" . WinUnderMouse))
return
WinGetPos, X_WuM, Y_WuM, Width_WuM, Height_WuM, ahk_id %WinUnderMouse%
; windows are retrieved in order from topmost to bottommost:
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
If NOT IsWindow(WinExist("ahk_id" . this_ID))
continue
WinGetTitle, title, ahk_id %this_ID%
If (title = "")
continue
WinGetPos, X, Y, Width, Height, ahk_id %this_ID%
If ((X+Width) < X_WuM)
continue
If (X > (X_WuM+Width_WuM))
continue
If ((Y+Height) < Y_WuM)
continue
If (Y > (Y_WuM+Height_WuM))
continue
If (this_ID = ID_WuM)
break
TopWins .= this_ID . " "
}
If (TopWins = "")
WinSet, Bottom,, ahk_id %WinUnderMouse%
else
{
; "WinSet, Top" doesn't always work
WinSet, AlwaysOnTop, On, ahk_id %WinUnderMouse%
Sleep, 30
WinSet, AlwaysOnTop, Off, ahk_id %WinUnderMouse%
}
}
;-----------------------------------------------------------------
; Check whether the window is in fact a window
; as opposed to the desktop or a menu, etc.
;-----------------------------------------------------------------
IsWindow(hWnd){
WinGet, dwStyle, Style, ahk_id %hWnd%
if ((dwStyle&0x08000000) || !(dwStyle&0x10000000)) {
return false
}
WinGet, dwExStyle, ExStyle, ahk_id %hWnd%
if (dwExStyle & 0x00000080) {
return false
}
WinGetClass, szClass, ahk_id %hWnd%
if (szClass = "TApplication") {
return false
}
return true
}
-
- Posts: 2
- Joined: 09 Dec 2018, 16:42
Re: Does IsWinPartiallyHidden exists?
Thanks everyone, but especially to GEV, yours works perfectly!
Re: Does IsWinPartiallyHidden exists?
Two functions that may be useful.
GetWindowRect function | Microsoft Docs
https://docs.microsoft.com/en-us/window ... windowrect
IntersectRect function | Microsoft Docs
https://docs.microsoft.com/en-us/window ... ersectrect
GetWindowRect function | Microsoft Docs
https://docs.microsoft.com/en-us/window ... windowrect
IntersectRect function | Microsoft Docs
https://docs.microsoft.com/en-us/window ... ersectrect
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA