center a window of a .bat file in the center of a screen without knowing the size of the screen?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
PAT06
Posts: 13
Joined: 18 May 2024, 14:16

center a window of a .bat file in the center of a screen without knowing the size of the screen?

21 May 2024, 08:26

Hi,

I'm looking for an AutoHotkey script to center a window from a .bat file in the center of a screen without knowing the screen size?
If possible integrate it into the .bat
I can not find...

Does anyone have this?!

Thanks
User avatar
CoffeeChaton
Posts: 37
Joined: 11 May 2024, 10:50

Re: center a window of a .bat file in the center of a screen without knowing the size of the screen?

21 May 2024, 08:59

Code: Select all

cmd_win_max() {
    Hwnd := WinExist("ahk_exe cmd.exe")
    ;                 ^^^^^^^^^^ use "WindowSpy.ahk" get it
    if (Hwnd == 0x0) {
        Return
    }

    aHwnd := "ahk_id " Hwnd
    WinActivate, %aHwnd%
    WinMaximize, %aHwnd%
    WinMove, %aHwnd%, , A_ScreenWidth / 2 , A_ScreenHeight / 2 ; , W, H
}
a screen without knowing the scree?
just use https://www.autohotkey.com/docs/v1/Variables.htm#Screen
A_ScreenHeight and A_ScreenWidth
center a window from a .bat file
Specifically?
I'm not sure what you mean.
Do you mean to adjust the windows of those files after using .bat to get a bunch of files and open them?
User avatar
mikeyww
Posts: 27261
Joined: 09 Sep 2014, 18:38

Re: center a window of a .bat file in the center of a screen without knowing the size of the screen?

21 May 2024, 09:04

Code: Select all

@echo off
D:\temp2\centerWindow.ahk "A"
Pause
EXIT

Code: Select all

#Requires AutoHotkey v1.1.33.11
#NoTrayIcon
If A_Args.Length()
 centerWindow(A_Args[1])
ExitApp

centerWindow(winTitle) {
 If WinExist(winTitle) {
  WinGetPos,,, w, h
  WinRestore
  WinMove (A_ScreenWidth  - w) / 2, (A_ScreenHeight - h) / 2
 }
}
PAT06
Posts: 13
Joined: 18 May 2024, 14:16

Re: center a window of a .bat file in the center of a screen without knowing the size of the screen?

21 May 2024, 09:19

Hi,

I would like to launch my "Install.bat" file and have it centered on the main monitor which does not always have the same size

Thanks
User avatar
CoffeeChaton
Posts: 37
Joined: 11 May 2024, 10:50

Re: center a window of a .bat file in the center of a screen without knowing the size of the screen?

21 May 2024, 09:42

Code: Select all

Run, % "D:\Install.bat"
cmd_win_max()
MsgBox, % "end"


cmd_win_max() {
    WinWait, % "ahk_exe cmd.exe",, 3 ; 3 sec
    if ErrorLevel
    {
        MsgBox, % "WinWait timed out"
        return
    }

    WinGetPos, ,, w, h
    WinRestore
    WinMove, (A_ScreenWidth  - w) / 2, (A_ScreenHeight - h) / 2
}
PAT06
Posts: 13
Joined: 18 May 2024, 14:16

Re: center a window of a .bat file in the center of a screen without knowing the size of the screen?

21 May 2024, 10:39

Hi,

Thanks, this one works

Code: Select all

Run, % "Install.bat"
cmd_win_max()
MsgBox, % "end"


cmd_win_max() {
    WinWait, % "ahk_exe cmd.exe",, 3 ; 3 sec
    if ErrorLevel
    {
        MsgBox, % "WinWait timed out"
        return
    }

    WinGetPos, ,, w, h
    WinRestore
    WinMove, (A_ScreenWidth  - w) / 2, (A_ScreenHeight - h) / 2
}
1st question :
For my information, what is it for (in red)
WinWait, % "ahk_exe cmd.exe",, 3 ; 3 sec

2nd question:
Is it normal for the bat window to randomly launch a shot to the right, a shot to the left very quickly and then center itself?
User avatar
CoffeeChaton
Posts: 37
Joined: 11 May 2024, 10:50

Re: center a window of a .bat file in the center of a screen without knowing the size of the screen?

21 May 2024, 10:53

1. 1st question :
Wait up to 3 seconds. If cmd.exe does not appear within 3 seconds, I will think there is something wrong and the user needs to confirm it. https://www.autohotkey.com/docs/v1/lib/WinWait.htm

2. 2nd question:
On my computer, it .just moved the window from point A to the middle.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 201 guests