Window Positioner

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Window Positioner

Post by hemsith14_ » 05 Jul 2022, 21:20

Hey, this might be an easy task, but it's still a bit advance for me, so I ask for your help.

I want to make a script that will position every window at the center of the screen while taking it's size into the consideration.
So, the distance between each corner of the screen will be the same with windows that are wide, and also narrow.

Also, I want these windows to be positioned so their most bottom part will always touch the bottom of the screen, taking their height into to consideration.
So, if the window is really high, it will be placed higher so it's bottom part will touch the bottom, and the opposite with a lower window.

Hope I was able to be clear enough, any help will be appreciated, thank you!

User avatar
mikeyww
Posts: 26593
Joined: 09 Sep 2014, 18:38

Re: Window Positioner

Post by mikeyww » 05 Jul 2022, 21:24

A centered window with its bottom at the screen's bottom sounds like a maximized window, or one that uses the full screen height.

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Window Positioner

Post by hemsith14_ » 05 Jul 2022, 21:30

Not always.

I have this so far:

Code: Select all

WinGetPos,,, Width, Height, A
TargetX := (A_ScreenWidth/2)-(Width/2)
TargetY := ; something here
WinMove, A, %TargetX%, %TargetY%
Now I just need to figure out how to do the height stuff.
Last edited by hemsith14_ on 05 Jul 2022, 21:42, edited 1 time in total.

User avatar
mikeyww
Posts: 26593
Joined: 09 Sep 2014, 18:38

Re: Window Positioner

Post by mikeyww » 05 Jul 2022, 21:37

Code: Select all

WinGet, win, List
Loop, %win% {
 WinExist("ahk_id" win%A_Index%)
 WinGetTitle, title
 If title in Program Manager,Start,Windows Task Manager,MainWindow
  Continue
 WinGet, winStyle, Style
 WinGet, state   , MinMax
 If !(winStyle & 0x10000000) || !title || state = MAX := 1
  Continue
 WinGetPos,,, width, height
 width := Min(width, A_ScreenWidth), height := Min(height, A_ScreenHeight)
 WinMove,,, (A_ScreenWidth - width) / 2, A_ScreenHeight - height, width, height
}
MsgBox, 64, Done, Done!

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Window Positioner

Post by hemsith14_ » 05 Jul 2022, 21:47

I tried your solution but it didn't work as expected

Maybe I didn't explain myself well enough

Imagine the file explorer, I want that the script will always position it's bottom part at the bottom of the screen, regardless of it's height (it can be really long or short).

I don't want to maximize the window or enlarge it in any way

Thanks either way!

P.S I'd appreciate if it could be a simple solution :D
Something like

Code: Select all

TargetY := ;Get bottom of window to touch bottom of screen

User avatar
mikeyww
Posts: 26593
Joined: 09 Sep 2014, 18:38

Re: Window Positioner

Post by mikeyww » 05 Jul 2022, 21:51

You tried the script?

Same thing:

Code: Select all

winTitle = ahk_class CabinetWClass
Run, explorer.exe
WinWait, %winTitle%
centerBottom(winTitle)
MsgBox, 64, Done, Done!

centerBottom(winTitle) {
 WinExist(winTitle)
 WinGet, state, MinMax
 If state = MAX := 1
  Return
 WinGetPos,,, width, height
 width := Min(width, A_ScreenWidth), height := Min(height, A_ScreenHeight)
 WinMove,,, (A_ScreenWidth - width) / 2, A_ScreenHeight - height, width, height
}

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Window Positioner

Post by hemsith14_ » 05 Jul 2022, 21:54

I solved it with the following line:

Code: Select all

TargetY := (A_ScreenHeight)-(Height)
Thanks either way for your help!

User avatar
mikeyww
Posts: 26593
Joined: 09 Sep 2014, 18:38

Re: Window Positioner

Post by mikeyww » 05 Jul 2022, 21:56

As I mentioned....

Post Reply

Return to “Ask for Help (v1)”