The below example shows how to drag a spot anywhere inside a window and make the whole window follow the mouse. Although it uses a GUI window, it could be adapted to work on any particular window, or even on all windows.
Code:
gui, -caption +0x40000 ; 0x40000 is WS_THICKFRAME (needed for AlwaysOnTop).
gui, add, text,, Text to display
gui, show
WinGet, GuiID, ID, A
WinSet, AlwaysOnTop, On, A
return
~LButton::
CoordMode, Mouse
MouseGetPos, MouseStartX, MouseStartY, MouseWin
if MouseWin <> %GuiID%
return
; Otherwise, track the mouse as the user drags it:
SetTimer, WatchMouse, 10
return
WatchMouse:
GetKeyState, LButtonState, LButton, P
if LButtonState = U ; Button has been released, so drag is complete.
{
SetTimer, WatchMouse, off
return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, MouseX, MouseY
DeltaX = %MouseX%
DeltaX -= %MouseStartX%
DeltaY = %MouseY%
DeltaY -= %MouseStartY%
MouseStartX = %MouseX% ; Update for the next timer call to this subroutine.
MouseStartY = %MouseY%
WinGetPos, GuiX, GuiY,,, ahk_id %GuiID%
GuiX += %DeltaX%
GuiY += %DeltaY%
SetWinDelay, -1 ; Makes the below move faster/smoother.
WinMove, ahk_id %GuiID%,, %GuiX%, %GuiY%
return