Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

XPSnap V1.1 Drag window to edges (Aero Snap)


  • Please log in to reply
10 replies to this topic
DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008
I searched the forum for a script that mimics Windows 7 Aero Snap. I found one that uses hot keys but I wanted one that uses the mouse. So I wrote one.
Click on the window titlebar and drag to any edge. The program takes into account the position and size of the taskbar.

I posted 2 scripts. The only difference between the two is that script 1 has no new window size preview and script 2 does. I also added a hotkey to exit the program on script 2.

Let me know of any problems. I only tested it in WinXP.

thanks
DataLife

Script 1 - Click titlebar and drag window to edge. Release LButton and window will resize. No new window size preview.
 
;Usage: Click on a titlebar and drag the window to any edge of the screen. Release the button while on the edge if you want to resize the window.
CoordMode, Mouse, Screen
SetFormat,float,6.0
*~LButton::
SysGet, MonitorWorkArea, MonitorWorkArea ;get dimensions of screen minus taskbar
CoordMode, Mouse, Relative
MouseGetPos,,YPosInWindow,hwnd ;is the mouse in the titlebar of the active window
CoordMode, Mouse, Screen
Return
*~Lbutton up::
CoordMode, Mouse, Screen
MouseGetPos, XstopPos, YstopPos, ;get the position of the mouse when the left click is released
sleep 100 ;Internet Explorer does not resize properly without a delay
;Preserve a 3X3 area on each corner to prevent confusion whether to position window on which side
;If (YstopPos>MonitorWorkAreaTop+3) mouse is at least 3 from top edge
;If (YstopPos<(MonitorWorkAreaBottom-3) mouse is at least 3 from bottom edge
;If (XstopPos>(MonitorWorkAreaLeft+3)) mouse is at least 3 from left edge
;If (XstopPos<(MonitorWorkAreaRight-3)) mouse is at least 3 from right edge
;If (YPosInWindow < 29) mouse is in titlebar
;Mouse is on left edge // determined by "If (XstopPos-MonitorWorkAreaLeft)<3)"
If ((XstopPos-MonitorWorkAreaLeft)<3)and(YstopPos>MonitorWorkAreaTop+3)and(YstopPos<(MonitorWorkAreaBottom-3))and(YPosInWindow < 29)
WinMove,ahk_id %hwnd%,,%MonitorWorkAreaLeft%,%MonitorWorkAreaTop%,((MonitorWorkAreaRight-MonitorWorkAreaLeft)/2),(MonitorWorkAreaBottom-MonitorWorkAreaTop)
;Mouse on Right edge // determined by "If (XstopPos>(MonitorWorkAreaRight-3))"
If (XstopPos>(MonitorWorkAreaRight-3))and(YstopPos>MonitorWorkAreaTop+3)and(YstopPos<(MonitorWorkAreaBottom-3))and(YPosInWindow < 29)
WinMove,ahk_id %hwnd%,,((MonitorWorkAreaRight+MonitorWorkAreaLeft)/2),MonitorWorkAreaTop,((MonitorWorkAreaRight-MonitorWorkAreaLeft)/2),(MonitorWorkAreaBottom-MonitorWorkAreaTop)
;Mouse is on the bottom edge // determined by "If (YstopPos>(MonitorWorkAreaBottom-3))"
If (YstopPos>(MonitorWorkAreaBottom-3))and(YstopPos<(MonitorWorkAreaBottom+1))and(XstopPos>(MonitorWorkAreaLeft+3))and(XstopPos<(MonitorWorkAreaRight-3))and(YPosInWindow < 29)
WinMove,ahk_id %hwnd%,,MonitorWorkAreaLeft,(((MonitorWorkAreaBottom-MonitorWorkAreaTop)/2)+MonitorWorkAreaTop) ,MonitorWorkAreaRight-MonitorWorkAreaLeft,((MonitorWorkAreaBottom-MonitorWorkAreaTop)/2)
;Mouse is on the top edge // determined by "If (YstopPos<(MonitorWorkAreaTop+3))"
If (YstopPos<(MonitorWorkAreaTop+3)) and (YstopPos>(MonitorWorkAreaTop-1))and(XstopPos>(MonitorWorkAreaLeft+3))and(XstopPos<(MonitorWorkAreaRight-3))and(YPosInWindow < 29)
WinMove,ahk_id %hwnd%,,MonitorWorkAreaLeft,MonitorWorkAreaTop,MonitorWorkAreaRight-MonitorWorkAreaLeft,((MonitorWorkAreaBottom-MonitorWorkAreaTop)/2)
Script 2 - Click titlebar and drag window to edge. Release LButton and window will resize. New window size preview.
 
;Usage: Click on a titlebar and drag the window to any edge of the screen. Release the button while on the edge if you want to resize the window.
;Hotkey to exit app: Control Alt e
#SingleInstance,Force
#NoTrayIcon
DetectHiddenWindows, On
;---------------------------------------------
;Invisible Gui with border
Gui 2: -SysMenu +ToolWindow -Border
Gui 2: Color, EEAA99
Gui 2: +LastFound
WinSet, TransColor, EEAA99
Gui 2: show, x5000 w1 h1 , GuiOutline ;show off the screen, then hide
WinGet, GuiOutline,id,GuiOutline
WinHide, ahk_id %GuiOutline%
;----------------------------------------------
*~LButton::
Proceed = 0 ;prevent GuiOutline from showing when clicking on the titlebar while the cursor is on an edge
break = 0 ;every release of the LButton up sets this to 1, so it has to be set to 0 every LButton down
SysGet, TitleBarHeight, 4 ;placed here in case height was changed after program started
SysGet, MonitorWorkArea, MonitorWorkArea ;placed here in case taskbar was moved to different side after program started
CoordMode, Mouse, Relative
MouseGetPos,,YPosInWindow,hwnd ;is mouse in titlebar ;get window id
CoordMode, Mouse, Screen
MouseGetPos,XPosStart,YPosStart
Loop
{
if break = 1
break
MouseGetPos, XPos1, YPos1,
;Hide GuiOutline if cursor is not on any edge and if mouse is in any corner
if (((XPos1>MonitorWorkAreaLeft)and(XPos1+1<MonitorWorkAreaRight))and(YPos1>MonitorWorkAreaTop and YPos1+1<MonitorWorkAreaBottom))or(XPos1=MonitorWorkAreaLeft and YPos1=MonitorWorkAreaTop)or(YPos1=MonitorWorkAreaTop and XPos1+1=MonitorWorkAreaRight)or(XPos1+1=MonitorWorkAreaRight and YPos1+1=MonitorWorkAreaBottom)or(XPos1=MonitorWorkAreaLeft and YPos1+1=MonitorWorkAreaBottom)
{
winhide,ahk_id %GuiOutline% ;hide GuiOutline when mouse is not on any edge
WinMove,ahk_id %GuiOutline%,,-1,-1, ;move hidden window offscreen, so when it is shown again on a different edge without releasing the Lbutton the window outline does not show for a split second on the previous edge it was shown on.
}
if (XPos1>MonitorWorkAreaLeft and (XPos1+1<MonitorWorkAreaRight)and(YPos1>MonitorWorkAreaTop+1)and(YPos1<MonitorWorkAreaBottom-1))
Proceed = 1 ;if the mouse starts at left or right edge and moves at least 1 and then back to the edge, GuiOutline is shown and window can resize
GetKeyState,KeyState,lbutton, P
if KeyState = D ;without this line, the GuiOutline shows up if LButton is click on the titlebar while on any edge
{
;Show GuiOutline on Left
If ((XPos1-MonitorWorkAreaLeft)<1)and(YPos1>MonitorWorkAreaTop+1)and(YPos1<(MonitorWorkAreaBottom-1))and(YPosInWindow < TitleBarHeight)and((XPosStart>XPos1)or(YPosStart< YPos1)or(Proceed = 1))
{
WinMove,ahk_id %GuiOutline%,,%MonitorWorkAreaLeft%,%MonitorWorkAreaTop%,((MonitorWorkAreaRight-MonitorWorkAreaLeft)/2),( MonitorWorkAreaBottom-MonitorWorkAreaTop)
if break = 1 ;break when Lbutton is release
break
Gui 2: show, noactivate
}
;Show GuiOutline on Right
If ((XPos1>MonitorWorkAreaRight-2)and(YPos1 > MonitorWorkAreaTop)and(YPos1<MonitorWorkAreaBottom-2)and(YPosInWindow<TitleBarHeight)and Proceed=1)
{
WinMove,ahk_id %GuiOutline%,,((MonitorWorkAreaRight+MonitorWorkAreaLeft)/2),MonitorWorkAreaTop,((MonitorWorkAreaRight-MonitorWorkAreaLeft)/2),(MonitorWorkAreaBottom-MonitorWorkAreaTop)
if break = 1 ;break when Lbutton is release
break
Gui 2: show, noactivate
}
;Show GuiOutline on Top
If (YPos1=MonitorWorkAreaTop)and(Proceed=1)and(XPos1>MonitorWorkAreaLeft)and(XPos1<MonitorWorkAreaRight-1)
{
WinMove,ahk_id %GuiOutLine%,,MonitorWorkAreaLeft,MonitorWorkAreaTop,MonitorWorkAreaRight-MonitorWorkAreaLeft,((MonitorWorkAreaBottom-MonitorWorkAreaTop)/2)
if break = 1 ;break when Lbutton is release
break
Gui 2: show, noactivate
}
;Show GuiOutline on Bottom
If (YPos1+1=MonitorWorkAreaBottom)and(Proceed=1)and(XPos1>MonitorWorkAreaLeft)and(XPos1+1<MonitorWorkAreaRight)
{
WinMove,ahk_id %GuiOutLine%,,MonitorWorkAreaLeft,(((MonitorWorkAreaBottom-MonitorWorkAreaTop)/2)+MonitorWorkAreaTop) ,MonitorWorkAreaRight-MonitorWorkAreaLeft,((MonitorWorkAreaBottom-MonitorWorkAreaTop)/2)
if break = 1 ;break when Lbutton is release
break
Gui 2: show, noactivate
}
WinSet,alwaysontop, on, ahk_id %guioutline%
}
}
Return
*~Lbutton up::
winhide,ahk_id %GuiOutline%
break = 1
;Mouse is on the left edge and not in a corner
If (XPos1=MonitorWorkAreaLeft)and(YPos1>MonitorWorkAreaTop+3)and(YPos1<(MonitorWorkAreaBottom-3))and(YPosInWindow<TitleBarHeight)and((XPosStart>XPos1)or(Proceed=1))
WinMove,ahk_id %hwnd%,,%MonitorWorkAreaLeft%,%MonitorWorkAreaTop%,((MonitorWorkAreaRight-MonitorWorkAreaLeft)/2),(MonitorWorkAreaBottom-MonitorWorkAreaTop)
;Mouse is on the right side and not in a corner
If (XPos1+1=MonitorWorkAreaRight)and(YPos1>(MonitorWorkAreaTop+3))and(YPos1<(MonitorWorkAreaBottom-3))and(YPosInWindow< TitleBarHeight)and((XPosStart<XPos1)or(Proceed=1))
WinMove,ahk_id %hwnd%,,((MonitorWorkAreaRight+MonitorWorkAreaLeft)/2),MonitorWorkAreaTop,((MonitorWorkAreaRight-MonitorWorkAreaLeft)/2),(MonitorWorkAreaBottom-MonitorWorkAreaTop)
;Mouse is on the bottom edge and not in a corner
If (YPos1 + 1 = MonitorWorkAreaBottom) and(XPos1>(MonitorWorkAreaLeft+3))and(XPos1<(MonitorWorkAreaRight-3))and(YPosInWindow<TitleBarHeight)and((YPosStart< YPos1)or(Proceed=1))
WinMove,ahk_id %hwnd%,,MonitorWorkAreaLeft,(((MonitorWorkAreaBottom-MonitorWorkAreaTop)/2)+MonitorWorkAreaTop) ,MonitorWorkAreaRight-MonitorWorkAreaLeft,((MonitorWorkAreaBottom-MonitorWorkAreaTop)/2)
;Mouse is on the top edge and not in a corner
If (YPos1 = MonitorWorkAreaTop)and(XPos1>(MonitorWorkAreaLeft+3))and(XPos1<(MonitorWorkAreaRight-3))and(YPosInWindow<titlebarheight)and((YPosStart>YPos1)or(Proceed=1))
WinMove,ahk_id %hwnd%,,MonitorWorkAreaLeft,MonitorWorkAreaTop,MonitorWorkAreaRight-MonitorWorkAreaLeft,((MonitorWorkAreaBottom-MonitorWorkAreaTop)/2)
return
^!e::
ExitApp
http://www.autohotke...Snap/XPSnap.ahk
Edit 02-23-2011 - - Added 2nd script
Edit 11-02-2011 - - Added link to the script on Autohotkey.net to enable linking with AutoHotkey.net Website Generator
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

1) Would be great if you could auto-snap a window when it reaches a certain position, without having to release LButton.
2) Check the behaviour I'm getting:
http://img541.images...7012/buggy0.png

 

* EDIT *

Topic for my version of the script (posts split from this topic):

http://www.autohotke...-go-off-screen/


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008
I added a script to the first post.

Script 1 resizes the window to half the screen when the window is dragged by the titlebar to the edge and released.

Script 2 does the same thing but also shows a preview of the area the window will take when the key is released. This one mimics Windows 7 Aero Snap functionality better.

DataLife
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

mKnight
  • Members
  • 28 posts
  • Last active: Aug 19 2014 08:44 AM
  • Joined: 19 Oct 2011
Absolutely good, I have been looking for one like this for my XP, it's really convenient :D .

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

Absolutely good, I have been looking for one like this for my XP, it's really convenient :D .


Thanks very much. I am glad someone is using this script.
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

Absolutely good, I have been looking for one like this for my XP, it's really convenient :D .


Thanks very much. I am glad someone is using this script.


Seems very useful and I wanted to see if I could use it for something (defining more zones, for example), but it doesn't work to me on Win7. When I drag a window, it displays snap space where I want it, but the window doesn't resize when I let go.

I use two monitors, and in the zones that Aero work, I can't notice XSnap doing anything - but in the zones where Aero would do nothing ("between" the computers) nothing happens when I release.

  • Guests
  • Last active:
  • Joined: --
Hi, is there a way to change your script so it works in mulit monitor environment ?

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

Seems very useful and I wanted to see if I could use it for something (defining more zones, for example), but it doesn't work to me on Win7. When I drag a window, it displays snap space where I want it, but the window doesn't resize when I let go.

I use two monitors, and in the zones that Aero work, I can't notice XSnap doing anything - but in the zones where Aero would do nothing ("between" the computers) nothing happens when I release.

I am using Windows 7 Home Premium and both scripts above work on a single monitor with Windows Aero Snap turned off.

I really don't have time right now to attempt to make it work with multiple monitors.

I have more pressing projects at the moment, after those I will see about making this work with multiple monitors.
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

Seems very useful and I wanted to see if I could use it for something (defining more zones, for example), but it doesn't work to me on Win7. When I drag a window, it displays snap space where I want it, but the window doesn't resize when I let go.

I use two monitors, and in the zones that Aero work, I can't notice XSnap doing anything - but in the zones where Aero would do nothing ("between" the computers) nothing happens when I release.

I am using Windows 7 Home Premium and both scripts above work on a single monitor with Windows Aero Snap turned off.

I really don't have time right now to attempt to make it work with multiple monitors.

I have more pressing projects at the moment, after those I will see about making this work with multiple monitors.


No worries, atleast then I know it should work with one monitor. If I have some time I'll play with it to see if I can make changes to allow for more snapzones, etc.

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
Just so you know I wrote a script that does support multiple monitors a little while back. You can see it here:

<!-- m -->http://www.autohotke...pic.php?t=72848<!-- m -->

Cheriyachen
  • Members
  • 5 posts
  • Last active: Mar 18 2014 05:23 AM
  • Joined: 28 Aug 2013

Thanks works like Win7 Cool grin.png now my Xp is rocking...