Skip to content

Instantly share code, notes, and snippets.

@pmp-p
Created February 7, 2024 02:18
Show Gist options
  • Save pmp-p/67a19efbcb1cf64d7decbf4fdbcf294b to your computer and use it in GitHub Desktop.
Save pmp-p/67a19efbcb1cf64d7decbf4fdbcf294b to your computer and use it in GitHub Desktop.
move win32 windows like on most Xwindows desktops (autoit)
#cs ----------------------------------------------------------------------------
move win32 windows like on most Xwindows desktops (autoit)
AutoIt Version: 3.3.8.1
Author: pmp-p
https://github.com/pmp-p
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <WinAPI.au3>
#include <Misc.au3>
Local $hDLL = DllOpen("user32.dll")
Func _WindowFromPoint($iX,$iY)
Local $stInt64,$aRet,$stPoint=DllStructCreate("long;long")
DllStructSetData($stPoint,1,$iX)
DllStructSetData($stPoint,2,$iY)
$stInt64=DllStructCreate("int64",DllStructGetPtr($stPoint))
$aRet=DllCall("user32.dll","hwnd","WindowFromPoint","int64",DllStructGetData($stInt64,1))
If @error Then Return SetError(2,@error,0)
If $aRet[0]=0 Then Return SetError(3,0,0)
Return $aRet[0]
EndFunc
Local $hControl, $hWin, $hOldWin, $aMousePos, $oldMousePos
$hOldWin = ""
While 1
; Wait until key is released.
While _IsPressed("12", $hDLL)
$aMousePos = MouseGetPos()
$hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1])
; Since _WindowFromPoint() can return 'sub' windows, or control handles, we should seek the owner window
$hWin=_WinAPI_GetAncestor($hControl,2)
$selected = WinGetTitle($hWin)
$announced = 0
$moving = 0
;wait mouse release
while _Ispressed("01",$hDLL) or _Ispressed("02",$hDLL)
if $moving <> 1 Then
WinSetState($selected,"",@SW_DISABLE )
$oldMousePos = MouseGetPos()
;ConsoleWrite("_IsPressed - Alt Key + Left Mouse was pressed." & "Window under mouse = " & WinGetTitle($hWin) & @CRLF)
$moving=1
EndIf
$aMousePos = MouseGetPos()
$dx = $aMousePos[0]- $oldMousePos[0]
$dy = $aMousePos[1]- $oldMousePos[1]
If $dx+$dy <> 0 Then
$wpos = WinGetPos($selected)
;move
if _Ispressed("01",$hDLL) then
WinMove( $selected , "", $wpos[0]+$dx , $wpos[1] + $dy )
Else
;so resize
WinMove( $selected , "", $wpos[0] , $wpos[1] , $wpos[2]+$dx ,$wpos[3]+$dy )
EndIf
$oldMousePos = $aMousePos
EndIf
sleep(4)
WEnd
WinSetState($selected,"",@SW_ENABLE )
$hOldWin = $hWin
Sleep(25)
WEnd
;ConsoleWrite("_IsPressed - Alt Key was released." & @CRLF)
Sleep(150)
WEnd
DllClose($hDLL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment