AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Moving a window via mouse without dragging its title bar

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Mon Nov 01, 2004 2:10 pm    Post subject: Moving a window via mouse without dragging its title bar Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
BoBo
Guest





PostPosted: Tue Nov 02, 2004 10:24 am    Post subject: Reply with quote

Available in the scripts showcase section ? Yes, or ?
Yes, yes, yes (the "bit" would answer @ Tron)
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Tue Nov 02, 2004 12:48 pm    Post subject: Reply with quote

It seems a little too obscure for that. But it's here in case anyone ever searches for such a thing.
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Sat Nov 13, 2004 3:55 am    Post subject: Universal drag? Reply with quote

I'm not a very expereienced AHK user, so my understanding of this script is superficial to say the least. I get the jist of it, though. Would it be possible to apply the concept to all windows, with a hotkey like ALT+Lbutton, instead of just the gui AHK creates? (Linux style)
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Sat Nov 13, 2004 3:05 pm    Post subject: Reply with quote

Here is a revised version that works on any window. Since there is more interest than I expected, I've put it here: http://www.autohotkey.com/docs/scripts/EasyWindowDrag.htm
Back to top
View user's profile Send private message Send e-mail
jonny



Joined: 13 Nov 2004
Posts: 3005
Location: Minnesota

PostPosted: Mon Nov 15, 2004 5:13 pm    Post subject: Reply with quote

Chris, did I ever tell you you're my hero? It took all of 30 seconds to get one of my fave *nix features ported. Shocked
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group