Jump to content

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

WinLimit (aka XP Snap): don't drag a window go off screen


  • Please log in to reply
28 replies to this topic
MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
####################################################################################
This old forum will be archived ( see https://autohotkey.c...s-decommission/ ).
For my up-to-date code and information, check the following links:
http://git.io/master | https://github.com/MasterFocus | http://masterfocus.ahk4.net/ | https://sites.google...masterfocusahk/
####################################################################################

 
* TOPIC SPLIT FROM http://www.autohotke...dges-aero-snap/ *
 
I have created this script, which should work fine (and without any kind of flickering).
It checks if the mouse is over the caption/titlebar whenever you click with LButton.
If yes, the timed subroutine keeps confining the mouse's limits until LButton is released.
It doesn't really "auto-snap" the window, but the effect is pratically the same.

Script:
    WinLimit

Description:
    When dragging any window, this script doesn't let any of its borders go off the screen.

Additional info:
    Originally "Posted 06 December 2010 - 07:17 PM", after this post: http://www.autohotke...-snap/?p=384971

Links:
    GitHub (see AutoHotkey - Others - WinLimit)

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

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
That is very nice. I like the feature of not be able to drag it off the screen.

One issue I see is if a window is already on one of the edges I am not able to grab the side of the window and make the window smaller. I can only make it larger.

With your script would you be able to make the window resize to half the screen when it gets to the edge? That was my whole purpose of my script was to be able to arrange two windows side by side taking up the full area of the screen

thanks
DataLife
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

That was my whole purpose


Hmmm... Sorry, I didn't knew this behaviour since I haven't experienced "Windows 7 Snap" so far (got XP at home).
You should be able to figure something out like this:

...
KeyWait, LButton
SetTimer, MyLabel, Off
Confine(0,0,0,0,0)
GoSub, AnotherLabel ; <------------
Return

You could add another label to check the window's position and resize it accordingly.


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

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
There are some nice ahk scripts out there that move the windows to the edges and resizes them very nicely. But they all use hotkeys.

I want to be able to "click and drag" to move a window to the edge then resize it to half the screen.

The problem is Windows is constantly keeping the window at its original size when it is being dragged around the screen. This is not seen until my script resizes the window when the mouse reaches the edge and when the lbutton is released.

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

Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

quoting MasterFocus's entire post ---- http://www.autohotke...-snap/?p=385184

I am desparately trying to get this script to work but it doesn't seem to do anything.  I have never seen this syntax ~*$LButton in any script i've ever used , what does it do??



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

Check the list of modifiers: http://www.autohotke...eys.htm#Symbols

 

All you'd have to do is drag a window normally (left-clicking its title bar).

How exactly it doesn't work for you? Have you changed anything?

 

EDIT: I have fixed some wrong behaviours after testing WinLimit on Windows 7.

Check GitHub for the new version (see page 1 of this topic for the link).


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

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.


Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

Check the list of modifiers: http://www.autohotke...eys.htm#Symbols

 

All you'd have to do is drag a window normally (left-clicking its title bar).

How exactly it doesn't work for you? Have you changed anything?

 

EDIT: I have fixed some wrong behaviours after testing WinLimit on Windows 7.

Check GitHub for the new version (see page 1 of this topic for the link).

I am using this script on a dual-monitor XP setup and when i say it doesn't work i mean literally nothing happens.  I can move windows like normal without any boundaries.  :-/  I did not change your code from what you posted.  I'll try the one on GitHUB now....

 

*EDIT :  Latest version worked great!!!!!   Last question, how could i change the script to only restrict the window to the top and bottom of the monitor but left and right sides acted normally? LOVING your script btw!!!!



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

Thanks, I'm glad you find the script useful.

I suppose you have to change    mouseX-winX    and    mouseX+scrW-winW-winX    to something else.

This should change the horizontal boundaries.
I didn't try, but a probable (ugly) solution would be to use 0 and something like 99999, respectively.


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

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.


Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

I think i found a problem with your script.  It seems that once a window touches the top of the screen that if i click and drag INSIDE the window that i can't move the mouse up at all.  So basically it seems like the script isn't correctly determinging if the cursor is in the titlebar or window edge.  :-/   This is an XP system btw. 

 

EDIT:  I tried playing with the errorlevel code and it looks like i never get any number back but 13?   Is there something special i need to do in order to get the SendMessage stuff working? sad.png



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

once a window touches the top of the screen that if i click and drag INSIDE the window that i can't move the mouse up at all

 
This is the expected behaviour, right? Here's what I understand from what you're saying: there is a certain window that can be dragged by clicking anywhere inside of it. Using this method, you're trying to drag one of its borders off the screen. That's exactly what my script prevents.

 

EDIT:  I tried playing with the errorlevel code and it looks like i never get any number back but 13?   Is there something special i need to do in order to get the SendMessage stuff working? sad.png

 
Last time I tried this script on WinXP (long time ago, validating only ErrorLevel=2), it worked as expected.

I only got ErrorLevel 13 with Notepad and Explorer windows on Win7.


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

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.


Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

No i'm sorry i'm not being clear.  For example, say you drag a windows explorer window to the top of the screen.  Now say you want to drag and highlight a bunch of files in the explorer window.  In this case i can drag the select box in all directions except up (since the top of the window is touching the top of the screen).  I think the real issue is that I only get an errorlevel 13.  I wonder if 64bit WinXP has some issue with scripts that use the SendMessages?  :(

 

 
This is the expected behaviour, right? Here's what I understand from what you're saying: there is a certain window that can be dragged by clicking anywhere inside of it. Using this method, you're trying to drag one of its borders off the screen. That's exactly what my script prevents.



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

I have just reproduced your behaviour on my 64bit Win7. I'll let you know if I come up with a solution for that.


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

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.


Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

I have just reproduced your behaviour on my 64bit Win7. I'll let you know if I come up with a solution for that.

Great!!  thank you for all your help as i really really want this script to work! :)



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

Hey Skrell,

 

A temporary fix would be to replace this line

If ( winW && winH )

with this one

If ( winX && winY && winW && winH )


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

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.


Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

Hey Skrell,

 

A temporary fix would be to replace this line

If ( winW && winH )

with this one

If ( winX && winY && winW && winH )

Ok that sort of works.  Seems to work better when the window is at the top of the screen, but never seems to work when it's on the bottom and i click and drag down while inside the window(ie. scrollbars/select highlight etc)