Here's an updated version with animation. Inspired by recent code by SKAN (thank you!). Enjoy!
Code:
; MoveIt - move windows with animation by ALT+LClick
; by Drugwash, June 7, 2009
#Persistent
DetectHiddenWindows, On
SysGet, mc, 80
if mc < 2, return
minW := 16 ; intermediary window size
VarSetCapacity(MI, 16*mc, 0)
hCB := RegisterCallback("MCB","", 4)
DllCall("EnumDisplayMonitors", UInt, NULL, UInt, NULL, UInt, hCB, UInt, 0)
SetTimer, move, 50
return
move:
If GetKeyState("Alt", "P") && GetKeyState("LButton", "P")
{
hWnd := WinExist("A")
WinGet, wstate, MinMax, A
If wstate = 1
{
wasmax = 1
SendMessage, 0x112, 0xF120,,, A ; SC_RESTORE
}
VarSetCapacity(Rect, 32, 0)
DllCall("GetWindowRect", UInt, hWnd, UInt, &Rect) ; get current window position
chMon := DllCall("MonitorFromRect", UInt, &Rect, UInt, 0x2) ; MONITOR_DEFAULTTONEAREST
Loop, %mc%
{
if (chMon = hMon%A_Index%)
{
cMon := A_Index
nMon := (A_Index = mc) ? "1" : A_Index + 1
break
}
}
aMon := (nMon = 1) ? nMon : cMon
mw := NumGet(MI, 8+16*(aMon-1), "Int")
mh := NumGet(MI, 12+16*(aMon-1), "Int")
intl := mw - minW//2
intt := mh//2 - minW//2
intr := intl + minW
intb := intt + minW
newl := NumGet(Rect, 0, "Int") - NumGet(MI, 0+16*(cMon-1), "Int") + NumGet(MI, 0+16*(nMon-1), "Int")
newt := NumGet(Rect, 4, "Int") - NumGet(MI, 4+16*(cMon-1), "Int") + NumGet(MI, 4+16*(nMon-1), "Int")
newr := NumGet(Rect, 8, "Int") - NumGet(MI, 0+16*(cMon-1), "Int") + NumGet(MI, 0+16*(nMon-1), "Int")
newb := NumGet(Rect, 12, "Int") - NumGet(MI, 4+16*(cMon-1), "Int") + NumGet(MI, 4+16*(nMon-1), "Int")
NumPut(intl, Rect, 16, "Int")
NumPut(intt, Rect, 20, "Int")
NumPut(intr, Rect, 24, "Int")
NumPut(intb, Rect, 28, "Int")
WinHide, ahk_id %hWnd%
DllCall("DrawAnimatedRects", UInt, hwnd, Int, 3, UInt, &Rect, UInt, &Rect+16) ; IDANI_CAPTION
DllCall("RtlMoveMemory", UInt, &Rect, UInt, &Rect+16, UInt, 16)
NumPut(newl, Rect, 16, "Int")
NumPut(newt, Rect, 20, "Int")
NumPut(newr, Rect, 24, "Int")
NumPut(newb, Rect, 28, "Int")
DllCall("DrawAnimatedRects", UInt, hwnd, Int, IDANI_CAPTION, UInt, &Rect, UInt, &Rect+16)
WinMove, ahk_id %hWnd%,, %newl%, %newt%
WinShow, ahk_id %hWnd%
}
If wasmax && (!GetKeyState("Alt", "P") || !GetKeyState("LButton", "P"))
{
wasmax = 0
SendMessage, 0x112, 0xF030,,, A ; SC_MAXIMIZE
}
return
MCB(hM, hDC, pRect, data)
{
global MI, hMon1, hMon2, hMon3, hMon4
static idx=1
hMon%idx% := hM
DllCall("RtlMoveMemory", UInt, &MI+16*(idx-1), UInt, pRect, UInt, 16)
idx++
return True
}