#Persistent SetTimer, chk, 50 return chk: If GetKeyState("Alt", "P") && GetKeyState("LButton", "P") PostMessage, 0xA1, 2,,, A return
Alt+LButton window dragging
Started by
lasmori
, Jan 13 2008 03:21 AM
19 replies to this topic
#16
-
Posted 27 May 2009 - 08:04 PM
This is my first post. I look forward to contributing and learning from the community!
I run 2 monitors. Sometimes a window is maximized in one monitor and I want to move it to the other monitor. It would be great if the script would also do the following:
1. Alt + Left Click the maximized window anywhere on the window (not just the title bar)
2. "Restore" the window
3. Allow for the dragging of the window without placing the cursor over the title bar (this is already done with the code)
Is this just an If statement that checks for whether the window is maximized? If it is, then it executes a different block of code.
I run 2 monitors. Sometimes a window is maximized in one monitor and I want to move it to the other monitor. It would be great if the script would also do the following:
1. Alt + Left Click the maximized window anywhere on the window (not just the title bar)
2. "Restore" the window
3. Allow for the dragging of the window without placing the cursor over the title bar (this is already done with the code)
Is this just an If statement that checks for whether the window is maximized? If it is, then it executes a different block of code.
#17
-
Posted 05 June 2009 - 05:21 PM
Here you are; it unpins the window allowing the drag (mouse cursor will be far off) and restores to maximized state when releasing left mouse button:
#Persistent SetTimer, chk, 50 return chk: If GetKeyState("Alt", "P") && GetKeyState("LButton", "P") { WinGet, wstate, MinMax, A If wstate = 1 { wasmax = 1 PostMessage, 0x112, 0xF120,,, A ; SC_RESTORE } PostMessage, 0xA1, 2,,, A } If GetKeyState("Alt", "P") && !GetKeyState("LButton", "P") && wasmax { wasmax = 0 PostMessage, 0x112, 0xF030,,, A ; SC_MAXIMIZE } return
#18
-
Posted 05 June 2009 - 08:19 PM
Here's an updated version with animation. Inspired by recent code by SKAN (thank you!). Enjoy!
; 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 }
#19
-
Posted 07 June 2009 - 09:43 PM
Here's another method that just tell the window it's title bar is being dragged by sending it the WM_NCLBUTTONDOWN message.
~!LButton::
{
MouseGetPos, OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 2
Control, Disable, , , ahk_id %OutputVarControl%
Result := DllCall("ReleaseCapture")
Control, Enable, , , ahk_id %OutputVarControl%
SendMessage, 161, 2, 0, , ahk_id %OutputVarWin%
return
}
#20
-
Posted 09 June 2009 - 02:21 PM