how to keep a window at the bottom always?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

how to keep a window at the bottom always?

09 Apr 2019, 06:10

I know that winset, bottom command gets the job done but sometimes a certain program has bullt-in behaviors of ignoring that script, so it pops back up time to time.

I want a program to be at the bottommost and stay like that until I press hotkey to cancel it.

is there a way to override all other attempts to get out of bottom mode for a program?
User avatar
jeeswg
Posts: 6901
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how to keep a window at the bottom always?

09 Apr 2019, 07:29

Just in case it helps, there is an AlwaysOnTop subcommand for WinSet.
You could set 'always on top' to off, for a window you want to be bottommost.

WinSet - Syntax & Usage | AutoHotkey
https://autohotkey.com/docs/commands/WinSet.htm
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: 865
Joined: 02 Oct 2013, 12:21

Re: how to keep a window at the bottom always?

09 Apr 2019, 15:03

Hi tatagi,

Would you let me know if the following code solves your problem?

Code: Select all

#NoEnv

WinIDs := GetAltTabWindows()
BottomID := WinIDs.Pop()  ; Get the bottom-most window
DllCall("RegisterShellHookWindow", "Ptr", A_ScriptHwnd)
MsgNum := DllCall("RegisterWindowMessage", "Str", "SHELLHOOK")
OnMessage(MsgNum, "ShellMessage")
Return

ShellMessage(wParam, lParam) {
   global BottomID
   if (wParam = 0x0004   ; HSHELL_WINDOWACTIVATED  = 0x0004 = 4
    || wParam = 0x8004)  ; HSHELL_RUDEAPPACTIVATED = HSHELL_WINDOWACTIVATED | HSHELL_HIGHBIT = 0x0004 | 0x8000 = 0x8004 = 32772
      WinSet, Bottom, , ahk_id %BottomID%
}

F3::  ; Disable monitoring of window activation
OnMessage(MsgNum, "")
Return

; https://autohotkey.com/board/topic/21657-alttab-window-list-get-a-list-of-alt-tab-windows/?p=600122

GetAltTabWindows() {
   static GW_OWNER := 4, WS_EX_TOOLWINDOW := 0x80, WS_EX_APPWINDOW := 0x40000
   PrevDetectHiddenWindows := A_DetectHiddenWindows
   DetectHiddenWindows, Off
   Windows := []
   WinGet, ID, List, , , Program Manager
   Loop, %ID% {
      OwnerID := ID%A_Index%
      Loop
         OwnerID := DllCall("GetWindow", "Ptr", OwnerID, "UInt", GW_OWNER, "Ptr")
      Until !DllCall("GetWindow", "Ptr", OwnerID, "UInt", GW_OWNER, "Ptr")
      OwnerID := OwnerID ? OwnerID : ID%A_Index%
      if (DllCall("GetLastActivePopup", "Ptr", OwnerID, "Ptr") = ID%A_Index%) {
         WinGet, ExStyle, ExStyle, % "ahk_id " ID%A_Index%
         if !((ExStyle & WS_EX_TOOLWINDOW) && !(ExStyle & WS_EX_APPWINDOW))
            Windows.Push(ID%A_Index%)
      }
   }
   DetectHiddenWindows, %PrevDetectHiddenWindows%
   Return Windows
}
Cheers!

- iPhilip
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
SkywardAxe
Posts: 1
Joined: 16 Sep 2022, 09:53

Re: how to keep a window at the bottom always?

16 Sep 2022, 09:57

Thanks iPhilip.
The code is great!!!
iPhilip
Posts: 865
Joined: 02 Oct 2013, 12:21

Re: how to keep a window at the bottom always?

16 Sep 2022, 11:39

@SkywardAxe, Happy to hear that it's useful to you. :)
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
shmu26
Posts: 7
Joined: 14 Dec 2015, 13:17

Re: how to keep a window at the bottom always?

08 Apr 2024, 08:56

iPhilip wrote:
09 Apr 2019, 15:03

Code: Select all

#NoEnv

WinIDs := GetAltTabWindows()
BottomID := WinIDs.Pop()  ; Get the bottom-most window
DllCall("RegisterShellHookWindow", "Ptr", A_ScriptHwnd)
MsgNum := DllCall("RegisterWindowMessage", "Str", "SHELLHOOK")
OnMessage(MsgNum, "ShellMessage")
Return

ShellMessage(wParam, lParam) {
   global BottomID
   if (wParam = 0x0004   ; HSHELL_WINDOWACTIVATED  = 0x0004 = 4
    || wParam = 0x8004)  ; HSHELL_RUDEAPPACTIVATED = HSHELL_WINDOWACTIVATED | HSHELL_HIGHBIT = 0x0004 | 0x8000 = 0x8004 = 32772
      WinSet, Bottom, , ahk_id %BottomID%
}

F3::  ; Disable monitoring of window activation
OnMessage(MsgNum, "")
Return

; https://autohotkey.com/board/topic/21657-alttab-window-list-get-a-list-of-alt-tab-windows/?p=600122

GetAltTabWindows() {
   static GW_OWNER := 4, WS_EX_TOOLWINDOW := 0x80, WS_EX_APPWINDOW := 0x40000
   PrevDetectHiddenWindows := A_DetectHiddenWindows
   DetectHiddenWindows, Off
   Windows := []
   WinGet, ID, List, , , Program Manager
   Loop, %ID% {
      OwnerID := ID%A_Index%
      Loop
         OwnerID := DllCall("GetWindow", "Ptr", OwnerID, "UInt", GW_OWNER, "Ptr")
      Until !DllCall("GetWindow", "Ptr", OwnerID, "UInt", GW_OWNER, "Ptr")
      OwnerID := OwnerID ? OwnerID : ID%A_Index%
      if (DllCall("GetLastActivePopup", "Ptr", OwnerID, "Ptr") = ID%A_Index%) {
         WinGet, ExStyle, ExStyle, % "ahk_id " ID%A_Index%
         if !((ExStyle & WS_EX_TOOLWINDOW) && !(ExStyle & WS_EX_APPWINDOW))
            Windows.Push(ID%A_Index%)
      }
   }
   DetectHiddenWindows, %PrevDetectHiddenWindows%
   Return Windows
}
Cheers!

- iPhilip
How do you use this script?
I mean, do you click on the window and then press a certain key combo, like with the more well-known "alwaysontop" function? I don't see that in the code, so I am wondering how it determines which window to act on? :think:

I am currently running Ubuntu with desktop in WSL2 on Windows 11, and I would like to set the Ubuntu window to always on bottom, so the desktop doesn't cover the Windows apps that I have open.
I can get the same result by setting each individual Windows app to "alwaysontop", but it is somewhat tedious.
iPhilip
Posts: 865
Joined: 02 Oct 2013, 12:21

Re: how to keep a window at the bottom always?

08 Apr 2024, 19:39

shmu26 wrote:
08 Apr 2024, 08:56
How do you use this script?
I mean, do you click on the window and then press a certain key combo, like with the more well-known "alwaysontop" function? I don't see that in the code, so I am wondering how it determines which window to act on? :think:

I am currently running Ubuntu with desktop in WSL2 on Windows 11, and I would like to set the Ubuntu window to always on bottom, so the desktop doesn't cover the Windows apps that I have open.
I can get the same result by setting each individual Windows app to "alwaysontop", but it is somewhat tedious.
@shmu26 When you run the script, the current bottom-most window will remain at the bottom, no matter which window you select. The OnMessage command monitors the selection of any desktop window. When a window is selected, the original bottom-most window is send to the bottom. The F3 hotkey turns off the monitoring.

I hope this helps to clarify things.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
iPhilip
Posts: 865
Joined: 02 Oct 2013, 12:21

Re: how to keep a window at the bottom always?

08 Apr 2024, 19:52

Here's a simpler version that doesn't use the GetAltTabWindows function (which is buggy):

Code: Select all

#NoEnv

DllCall("RegisterShellHookWindow", "Ptr", A_ScriptHwnd)
MsgNum := DllCall("RegisterWindowMessage", "Str", "SHELLHOOK")
return

F2::
BottomID := WinExist("A")
WinSet, Bottom, , ahk_id %BottomID%
OnMessage(MsgNum, "ShellMessage")
Return

F3::  ; Disable monitoring of window activation
OnMessage(MsgNum, "")
Return

ShellMessage(wParam) {
   global BottomID
   if (wParam = 0x0004   ; HSHELL_WINDOWACTIVATED  = 0x0004 = 4
    || wParam = 0x8004)  ; HSHELL_RUDEAPPACTIVATED = HSHELL_WINDOWACTIVATED | HSHELL_HIGHBIT = 0x0004 | 0x8000 = 0x8004 = 32772
      WinSet, Bottom, , ahk_id %BottomID%
}
The F2 hotkey send the active window to the bottom and keeps it there. The F3 hotkey disables that.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
shmu26
Posts: 7
Joined: 14 Dec 2015, 13:17

Re: how to keep a window at the bottom always?

08 Apr 2024, 21:41

Thanks! Will this work on the old version of AHK?
Answer: Yes. This is a great script!
shmu26
Posts: 7
Joined: 14 Dec 2015, 13:17

Re: how to keep a window at the bottom always?

08 Apr 2024, 23:10

iPhilip wrote:
08 Apr 2024, 19:52
Here's a simpler version that doesn't use the GetAltTabWindows function (which is buggy):

Code: Select all

#NoEnv

DllCall("RegisterShellHookWindow", "Ptr", A_ScriptHwnd)
MsgNum := DllCall("RegisterWindowMessage", "Str", "SHELLHOOK")
return

F2::
BottomID := WinExist("A")
WinSet, Bottom, , ahk_id %BottomID%
OnMessage(MsgNum, "ShellMessage")
Return

F3::  ; Disable monitoring of window activation
OnMessage(MsgNum, "")
Return

ShellMessage(wParam) {
   global BottomID
   if (wParam = 0x0004   ; HSHELL_WINDOWACTIVATED  = 0x0004 = 4
    || wParam = 0x8004)  ; HSHELL_RUDEAPPACTIVATED = HSHELL_WINDOWACTIVATED | HSHELL_HIGHBIT = 0x0004 | 0x8000 = 0x8004 = 32772
      WinSet, Bottom, , ahk_id %BottomID%
}
The F2 hotkey send the active window to the bottom and keeps it there. The F3 hotkey disables that.
Perfect. Works also on the old version of AHK.
iPhilip
Posts: 865
Joined: 02 Oct 2013, 12:21

Re: how to keep a window at the bottom always?

09 Apr 2024, 00:01

Great! :)
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 152 guests