Here is my current script:
Code: Select all
#Persistent
OnWinActiveChange(hWinEventHook, vEvent, hWnd)
{
static _ := DllCall("user32\SetWinEventHook", UInt, 0x3, UInt, 0x3, Ptr, 0, Ptr, RegisterCallback("OnWinActiveChange"), UInt, 0, UInt, 0, UInt, 0, Ptr)
DetectHiddenWindows, On
WinGetClass, vWinClass, % "ahk_id " hWnd
CenterActiveWindow()
}
CenterActiveWindow()
{
winHandle := WinExist("A")
VarSetCapacity(monitorInfo, 40), NumPut(40, monitorInfo)
monitorHandle := DllCall("MonitorFromWindow", "Ptr", winHandle, "UInt", 0x2)
DllCall("GetMonitorInfo", "Ptr", monitorHandle, "Ptr", &monitorInfo)
workLeft := NumGet(monitorInfo, 20, "Int")
workTop := NumGet(monitorInfo, 24, "Int")
workRight := NumGet(monitorInfo, 28, "Int")
workBottom := NumGet(monitorInfo, 32, "Int")
WinGetPos,,, W, H, A
WinGet, Style, Style, A
if (Style & 0x80000)
{
WinMove, A,, workLeft + (workRight - workLeft) // 2 - W // 2, workTop + (workBottom - workTop) // 2 - H // 2
}
}
OnWinActiveChange(0, 0, 0)
Loop
Sleep, 100