Code: Select all
; GetCurrentMonitor: Gets the current monitor index based upon mouse position
GetCurrentMonitor() {
CoordMode "Mouse", "Screen"
MouseGetPos &MouseX, &MouseY
NumMonitors := MonitorGetCount()
Loop NumMonitors {
MonitorGet A_Index, &MonitorLeft, &MonitorTop, &MonitorRight, &MonitorBottom
If (MouseX >= MonitorLeft And MouseX < MonitorRight And MouseY >= MonitorTop And MouseY < MonitorBottom)
Return A_Index
}
Return 1 ; should never really execute
}
; ShowCentered: show Gui in centre of current monitor.
ShowCentered(Gui) {
CurrentMonitor := GetCurrentMonitor()
MonitorGet CurrentMonitor, &MonitorLeft, &MonitorTop, &MonitorRight, &MonitorBottom
Gui.GetClientPos(&x, &y, &w, &h)
x := Integer(((MonitorRight - MonitorLeft - w) / 2) + MonitorLeft)
y := Integer(((MonitorBottom - MonitorTop - h) / 2) + MonitorTop)
Gui.Show("x" x " y" y)
}